Merge lp:~nuclearbob/utah/getfiles into lp:utah

Proposed by Max Brustkern
Status: Merged
Approved by: Joe Talbott
Approved revision: 705
Merged at revision: 752
Proposed branch: lp:~nuclearbob/utah/getfiles
Merge into: lp:utah
Diff against target: 183 lines (+81/-13)
6 files modified
examples/run_install_test.py (+5/-0)
examples/run_test_cobbler.py (+5/-0)
examples/run_test_vm.py (+5/-0)
examples/run_utah_tests.py (+5/-0)
utah/provisioning/provisioning.py (+34/-13)
utah/run.py (+27/-0)
To merge this branch: bzr merge lp:~nuclearbob/utah/getfiles
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+134743@code.launchpad.net

Description of the change

This branch adds -f and -o options to run_utah_tests.py. -f specified a file or directory to retrieve from the provisioned system, and can be specified multiple times. -o specified the output directory, which defaults to /var/log/utah/{systemname} and will be created if necessary.

To post a comment you must log in.
Revision history for this message
Max Brustkern (nuclearbob) wrote :

There's also a fix for some logic for automatically downloading ISOs that I made while testing this. It's very small, so I wasn't sure if it needed a new branch.

Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good to me. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/run_install_test.py'
2--- examples/run_install_test.py 2012-11-08 14:51:09 +0000
3+++ examples/run_install_test.py 2012-11-16 20:52:18 +0000
4@@ -65,6 +65,11 @@
5 help='Enable debug logging')
6 parser.add_argument('-j', '--json', action='store_true',
7 help='Enable json logging (default is YAML)')
8+ parser.add_argument('-f', '--files', action='append',
9+ help='File or directory to copy from test system ')
10+ parser.add_argument('-o', '--outdir',
11+ help=('Directory to store locally copied files '
12+ '(Default is ' + config.logpath + '/machine-name)'))
13 parser.add_argument('--diskbus', metavar='DISKBUS',
14 choices=('virtio', 'sata', 'ide'),
15 help=('Disk bus to use for customvm installation '
16
17=== modified file 'examples/run_test_cobbler.py'
18--- examples/run_test_cobbler.py 2012-11-14 19:56:48 +0000
19+++ examples/run_test_cobbler.py 2012-11-16 20:52:18 +0000
20@@ -46,6 +46,11 @@
21 help='Enable debug logging')
22 parser.add_argument('-j', '--json', action='store_true',
23 help='Enable json logging (default is YAML)')
24+ parser.add_argument('-f', '--files', action='append',
25+ help='File or directory to copy from test system ')
26+ parser.add_argument('-o', '--outdir',
27+ help=('Directory to store locally copied files '
28+ '(Default is ' + config.logpath + '/machine-name)'))
29 parser.add_argument('--rewrite', choices=('all', 'minimal', 'casperonly',
30 'none'), help='Enable or disable automatic '
31 'configuration rewriting')
32
33=== modified file 'examples/run_test_vm.py'
34--- examples/run_test_vm.py 2012-11-14 16:14:38 +0000
35+++ examples/run_test_vm.py 2012-11-16 20:52:18 +0000
36@@ -40,6 +40,11 @@
37 help='Enable debug logging')
38 parser.add_argument('-j', '--json', action='store_true',
39 help='Enable json logging (default is YAML)')
40+ parser.add_argument('-f', '--files', action='append',
41+ help='File or directory to copy from test system ')
42+ parser.add_argument('-o', '--outdir',
43+ help=('Directory to store locally copied files '
44+ '(Default is ' + config.logpath + '/machine-name)'))
45 return parser
46
47
48
49=== modified file 'examples/run_utah_tests.py'
50--- examples/run_utah_tests.py 2012-11-14 18:12:13 +0000
51+++ examples/run_utah_tests.py 2012-11-16 20:52:18 +0000
52@@ -66,6 +66,11 @@
53 help='Enable debug logging')
54 parser.add_argument('-j', '--json', action='store_true',
55 help='Enable json logging (default is YAML)')
56+ parser.add_argument('-f', '--files', action='append',
57+ help='File or directory to copy from test system ')
58+ parser.add_argument('-o', '--outdir',
59+ help=('Directory to store locally copied files '
60+ '(Default is ' + config.logpath + '/machine-name)'))
61 parser.add_argument('--diskbus', metavar='DISKBUS',
62 choices=('virtio', 'sata', 'ide'),
63 help=('Disk bus to use for customvm installation '
64
65=== modified file 'utah/provisioning/provisioning.py'
66--- utah/provisioning/provisioning.py 2012-11-14 18:12:54 +0000
67+++ utah/provisioning/provisioning.py 2012-11-16 20:52:18 +0000
68@@ -17,7 +17,11 @@
69 import paramiko
70 import re
71 import apt.cache
72+
73 from glob import glob
74+from stat import S_ISDIR
75+
76+import utah.timeout
77
78 from utah.commandstr import commandstr
79 from utah.iso import ISO
80@@ -28,7 +32,6 @@
81 from utah.preseed import Preseed
82 from utah.provisioning.exceptions import UTAHProvisioningException
83 from utah.retry import retry
84-import utah.timeout
85 from utah import config
86
87
88@@ -152,9 +155,7 @@
89
90 if image is None:
91 image = config.image
92- if image is None:
93- self.image = None
94- elif image.endswith('.iso'):
95+ if image is None or image.endswith('.iso'):
96 self.image = ISO(arch=arch,
97 dlpercentincrement=self.dlpercentincrement,
98 image=image, installtype=installtype, logger=self.logger,
99@@ -742,19 +743,39 @@
100 finally:
101 sftp_client.close()
102
103- def downloadfilesindir(self, dirname, target=os.path.normpath('/tmp/')):
104- """
105- Copy all files in dirname on the machine to target on the host.
106- Recursion is not yet implemented.
107- """
108- # TODO: Implement recursion
109+ def downloadfilesrecursive(self, files, target=os.path.normpath('/tmp/')):
110+ """
111+ Recursively copy all files in files to the target directory target.
112+ """
113 self.activecheck()
114 self.ssh_client.connect(self.name,
115 key_filename=config.sshprivatekey)
116 sftp_client = self.ssh_client.open_sftp()
117- files = [os.path.join(dirname, myfile)
118- for myfile in sftp_client.listdir(dirname)]
119- self.downloadfiles(files, target)
120+ myfiles = []
121+
122+ if isinstance(files, basestring):
123+ files = [files]
124+
125+ for myfile in files:
126+ newtarget = os.path.join(target, os.path.basename(myfile))
127+ if S_ISDIR(sftp_client.stat(myfile).st_mode):
128+ self.logger.debug(myfile + ' is a directory, recursing')
129+ if not os.path.isdir(newtarget):
130+ self.logger.debug('Attempting to create ' + newtarget)
131+ os.makedirs(newtarget)
132+ myfiles = [os.path.join(myfile, x)
133+ for x in sftp_client.listdir(myfile)]
134+# for basename in sftp_client.listdir(dirname):
135+# myfile = os.path.join(dirname, basename)
136+# if S_ISDIR(sftp_client.stat(myfile).st_mode):
137+# if not os.path.isdir(newtarget):
138+# os.makedirs(newtarget)
139+# self.downloadfilesrecursive(myfile, newtarget)
140+# else:
141+# myfiles.append(myfile)
142+ self.downloadfilesrecursive(myfiles, newtarget)
143+ else:
144+ self.downloadfiles(myfile, newtarget)
145
146 def destroy(self, *args, **kw):
147 """
148
149=== modified file 'utah/run.py'
150--- utah/run.py 2012-10-25 11:54:11 +0000
151+++ utah/run.py 2012-11-16 20:52:18 +0000
152@@ -59,4 +59,31 @@
153 machine.logger.info('Test log copied to ' + locallog)
154 locallogs.append(locallog)
155
156+ if args.files is not None:
157+ try:
158+ locallogs += getfiles(args, machine)
159+ except Exception as err:
160+ machine.logger.warning('Failed to download files: ' + str(err))
161+
162 return exitstatus, locallogs
163+
164+
165+def getfiles(args, machine):
166+ if args.outdir is None:
167+ outdir = os.path.join(config.logpath, machine.name)
168+ else:
169+ outdir = args.outdir
170+ if not os.path.isdir(outdir):
171+ os.makedirs(outdir)
172+
173+ machine.downloadfilesrecursive(args.files, outdir)
174+
175+ localfiles = []
176+
177+ for mydir, dirs, files in os.walk(outdir):
178+ myfiles = [os.path.join(mydir, x) for x in files]
179+ for myfile in myfiles:
180+ localfiles.append(myfile)
181+
182+ return localfiles
183+

Subscribers

People subscribed via source and target branches