Merge lp:~chris.macnaughton/mojo/py3003 into lp:~ost-maintainers/mojo/py3
- py3003
- Merge into py3
Proposed by
Chris MacNaughton
Status: | Needs review |
---|---|
Proposed branch: | lp:~chris.macnaughton/mojo/py3003 |
Merge into: | lp:~ost-maintainers/mojo/py3 |
Diff against target: |
217 lines (+56/-13) 5 files modified
mojo/cli.py (+1/-1) mojo/contain.py (+26/-6) mojo/juju/debuglogs.py (+7/-1) mojo/juju/status.py (+9/-2) mojo/phase.py (+13/-3) |
To merge this branch: | bzr merge lp:~chris.macnaughton/mojo/py3003 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charm Testing Maintainers | Pending | ||
Review via email: mp+337159@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 470. By Chris MacNaughton
-
cleanup error output
Revision history for this message
Colin Watson (cjwatson) wrote : | # |
Any reason not to use universal_
Unmerged revisions
- 470. By Chris MacNaughton
-
cleanup error output
- 469. By Chris MacNaughton
-
add more decode calls
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'mojo/cli.py' | |||
2 | --- mojo/cli.py 2018-01-22 06:58:28 +0000 | |||
3 | +++ mojo/cli.py 2018-02-05 16:24:42 +0000 | |||
4 | @@ -645,7 +645,7 @@ | |||
5 | 645 | logging.error(e) | 645 | logging.error(e) |
6 | 646 | sys.exit(1) | 646 | sys.exit(1) |
7 | 647 | except mojo.phase.ScriptPhaseException as e: | 647 | except mojo.phase.ScriptPhaseException as e: |
9 | 648 | logging.error(e.output) | 648 | logging.error(e) |
10 | 649 | sys.exit(1) | 649 | sys.exit(1) |
11 | 650 | except mojo.exceptions.ConfigNotFoundException as e: | 650 | except mojo.exceptions.ConfigNotFoundException as e: |
12 | 651 | logging.error(e.message) | 651 | logging.error(e.message) |
13 | 652 | 652 | ||
14 | === modified file 'mojo/contain.py' | |||
15 | --- mojo/contain.py 2018-01-18 10:23:15 +0000 | |||
16 | +++ mojo/contain.py 2018-02-05 16:24:42 +0000 | |||
17 | @@ -11,6 +11,7 @@ | |||
18 | 11 | import os | 11 | import os |
19 | 12 | import platform | 12 | import platform |
20 | 13 | import pwd | 13 | import pwd |
21 | 14 | import six | ||
22 | 14 | import shlex | 15 | import shlex |
23 | 15 | import shutil | 16 | import shutil |
24 | 16 | import subprocess | 17 | import subprocess |
25 | @@ -568,11 +569,17 @@ | |||
26 | 568 | if state: | 569 | if state: |
27 | 569 | cmd = ('sudo', 'lxc-info', '-s', '-n', self.container_name) | 570 | cmd = ('sudo', 'lxc-info', '-s', '-n', self.container_name) |
28 | 570 | logging.debug("Running command: {}".format(" ".join(cmd))) | 571 | logging.debug("Running command: {}".format(" ".join(cmd))) |
30 | 571 | containers = yaml.safe_load(subprocess.check_output(cmd)) | 572 | output = subprocess.check_output(cmd) |
31 | 573 | if six.PY3: | ||
32 | 574 | output = output.decode('utf-8') | ||
33 | 575 | containers = yaml.safe_load(output) | ||
34 | 572 | # lxc-info shows 'state' (precise) or 'State' (newer) | 576 | # lxc-info shows 'state' (precise) or 'State' (newer) |
35 | 573 | return state in containers.get('state', containers.get('State', {})) | 577 | return state in containers.get('state', containers.get('State', {})) |
36 | 574 | cmd = ('sudo', 'lxc-ls', '-1') | 578 | cmd = ('sudo', 'lxc-ls', '-1') |
38 | 575 | containers = subprocess.check_output(cmd).split() | 579 | output = subprocess.check_output(cmd) |
39 | 580 | if six.PY3: | ||
40 | 581 | output = output.decode('utf-8') | ||
41 | 582 | containers = output.split() | ||
42 | 576 | return self.container_name in containers | 583 | return self.container_name in containers |
43 | 577 | 584 | ||
44 | 578 | @ensure_defined | 585 | @ensure_defined |
45 | @@ -633,7 +640,10 @@ | |||
46 | 633 | logging.debug("Running command: {}".format(" ".join(cmd))) | 640 | logging.debug("Running command: {}".format(" ".join(cmd))) |
47 | 634 | 641 | ||
48 | 635 | # lxc-info -i will return a row for each IP, plus a newline | 642 | # lxc-info -i will return a row for each IP, plus a newline |
50 | 636 | found_ips = subprocess.check_output(cmd).split('\n') | 643 | output = subprocess.check_output(cmd) |
51 | 644 | if six.PY3: | ||
52 | 645 | output = output.decode('utf-8') | ||
53 | 646 | found_ips = output.split('\n') | ||
54 | 637 | if len(found_ips) > 1: | 647 | if len(found_ips) > 1: |
55 | 638 | networking = True | 648 | networking = True |
56 | 639 | else: | 649 | else: |
57 | @@ -645,7 +655,10 @@ | |||
58 | 645 | if attempts >= max_attempts: | 655 | if attempts >= max_attempts: |
59 | 646 | logging.error("No networking after {} attempts, giving up".format(attempts)) | 656 | logging.error("No networking after {} attempts, giving up".format(attempts)) |
60 | 647 | cmd = ('sudo', 'lxc-info', '-n', self.container_name) | 657 | cmd = ('sudo', 'lxc-info', '-n', self.container_name) |
62 | 648 | lxc_info_output = subprocess.check_output(cmd).split('\n') | 658 | output = subprocess.check_output(cmd) |
63 | 659 | if six.PY3: | ||
64 | 660 | output = output.decode('utf-8') | ||
65 | 661 | lxc_info_output = output.split('\n') | ||
66 | 649 | logging.error("lxc-info output: {}".format(lxc_info_output)) | 662 | logging.error("lxc-info output: {}".format(lxc_info_output)) |
67 | 650 | return False | 663 | return False |
68 | 651 | return True | 664 | return True |
69 | @@ -694,6 +707,8 @@ | |||
70 | 694 | "".format(self.container_name, ' '.join(command))) | 707 | "".format(self.container_name, ' '.join(command))) |
71 | 695 | try: | 708 | try: |
72 | 696 | output = subprocess.check_output(cmd, stderr=stderr) | 709 | output = subprocess.check_output(cmd, stderr=stderr) |
73 | 710 | if six.PY3: | ||
74 | 711 | output = output.decode('utf-8') | ||
75 | 697 | if output.strip(): | 712 | if output.strip(): |
76 | 698 | logging.info(output) | 713 | logging.info(output) |
77 | 699 | finally: | 714 | finally: |
78 | @@ -791,9 +806,12 @@ | |||
79 | 791 | return False | 806 | return False |
80 | 792 | 807 | ||
81 | 793 | def create_user(self, user): | 808 | def create_user(self, user): |
82 | 809 | output = subprocess.check_output( | ||
83 | 810 | ['getent', 'passwd', user]) | ||
84 | 811 | if six.PY3: | ||
85 | 812 | output = output.decode('utf-8') | ||
86 | 794 | (username, shadow, uid, | 813 | (username, shadow, uid, |
89 | 795 | gid, name, home, shell) = subprocess.check_output( | 814 | gid, name, home, shell) = output.split(':') |
88 | 796 | ['getent', 'passwd', user]).split(':') | ||
90 | 797 | # if the uid exists update the name to match the caller | 815 | # if the uid exists update the name to match the caller |
91 | 798 | try: | 816 | try: |
92 | 799 | command = "useradd --home {} --create-home --uid {} {}" \ | 817 | command = "useradd --home {} --create-home --uid {} {}" \ |
93 | @@ -843,6 +861,8 @@ | |||
94 | 843 | "project. Running command without a container: {}" | 861 | "project. Running command without a container: {}" |
95 | 844 | "".format(command)) | 862 | "".format(command)) |
96 | 845 | output = subprocess.check_output(command, stderr=subprocess.STDOUT) | 863 | output = subprocess.check_output(command, stderr=subprocess.STDOUT) |
97 | 864 | if six.PY3: | ||
98 | 865 | output = output.decode('utf-8') | ||
99 | 846 | if output.strip(): | 866 | if output.strip(): |
100 | 847 | logging.info(output) | 867 | logging.info(output) |
101 | 848 | 868 | ||
102 | 849 | 869 | ||
103 | === modified file 'mojo/juju/debuglogs.py' | |||
104 | --- mojo/juju/debuglogs.py 2017-01-11 02:34:42 +0000 | |||
105 | +++ mojo/juju/debuglogs.py 2018-02-05 16:24:42 +0000 | |||
106 | @@ -1,6 +1,7 @@ | |||
107 | 1 | import ast | 1 | import ast |
108 | 2 | import logging | 2 | import logging |
109 | 3 | import subprocess | 3 | import subprocess |
110 | 4 | import six | ||
111 | 4 | import yaml | 5 | import yaml |
112 | 5 | 6 | ||
113 | 6 | import mojo.juju | 7 | import mojo.juju |
114 | @@ -97,11 +98,16 @@ | |||
115 | 97 | '[ -z "$PYTHON" ] && {{ echo ERROR: No python3 or python found. ; exit 1 ; }} ; ' | 98 | '[ -z "$PYTHON" ] && {{ echo ERROR: No python3 or python found. ; exit 1 ; }} ; ' |
116 | 98 | '$PYTHON -c "import glob; print(glob.glob(\'{}\'))"'.format(path)] | 99 | '$PYTHON -c "import glob; print(glob.glob(\'{}\'))"'.format(path)] |
117 | 99 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | 100 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
118 | 101 | if six.PY3: | ||
119 | 102 | output = output.decode('utf-8') | ||
120 | 100 | return ast.literal_eval(output) | 103 | return ast.literal_eval(output) |
121 | 101 | 104 | ||
122 | 102 | def _run_remote_command(self, unit, command, sanitized_path_list): | 105 | def _run_remote_command(self, unit, command, sanitized_path_list): |
123 | 103 | cmd = ['juju', 'run', '--unit', unit, "{} {}".format(command, " ".join(sanitized_path_list))] | 106 | cmd = ['juju', 'run', '--unit', unit, "{} {}".format(command, " ".join(sanitized_path_list))] |
125 | 104 | return subprocess.check_output(cmd, stderr=subprocess.STDOUT) | 107 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
126 | 108 | if six.PY3: | ||
127 | 109 | output = output.decode('utf-8') | ||
128 | 110 | return output | ||
129 | 105 | 111 | ||
130 | 106 | def _gather_logs(self): | 112 | def _gather_logs(self): |
131 | 107 | output = [] | 113 | output = [] |
132 | 108 | 114 | ||
133 | === modified file 'mojo/juju/status.py' | |||
134 | --- mojo/juju/status.py 2018-01-25 09:10:29 +0000 | |||
135 | +++ mojo/juju/status.py 2018-02-05 16:24:42 +0000 | |||
136 | @@ -42,7 +42,10 @@ | |||
137 | 42 | 42 | ||
138 | 43 | cmd.extend(command) | 43 | cmd.extend(command) |
139 | 44 | try: | 44 | try: |
141 | 45 | return subprocess.check_output(cmd) | 45 | output = subprocess.check_output(cmd) |
142 | 46 | if six.PY3: | ||
143 | 47 | output = output.decode('utf-8') | ||
144 | 48 | return output | ||
145 | 46 | except subprocess.CalledProcessError as cpe: | 49 | except subprocess.CalledProcessError as cpe: |
146 | 47 | if command_timeout is not None: | 50 | if command_timeout is not None: |
147 | 48 | # magic numbers here as per timeout(1) | 51 | # magic numbers here as per timeout(1) |
148 | @@ -474,7 +477,11 @@ | |||
149 | 474 | """ Parses the output of 'juju controllers' returning the controller version for the current controller. | 477 | """ Parses the output of 'juju controllers' returning the controller version for the current controller. |
150 | 475 | Returns: The controller version reported by Juju | 478 | Returns: The controller version reported by Juju |
151 | 476 | """ | 479 | """ |
153 | 477 | controllers = yaml.safe_load(subprocess.check_output(['juju', 'controllers', '--format', 'yaml'])) | 480 | output = subprocess.check_output( |
154 | 481 | ['juju', 'controllers', '--format', 'yaml']) | ||
155 | 482 | if six.PY3: | ||
156 | 483 | output = output.decode('utf-8') | ||
157 | 484 | controllers = yaml.safe_load(output) | ||
158 | 478 | current_controller = controllers['current-controller'] | 485 | current_controller = controllers['current-controller'] |
159 | 479 | return controllers['controllers'][current_controller]['agent-version'] | 486 | return controllers['controllers'][current_controller]['agent-version'] |
160 | 480 | 487 | ||
161 | 481 | 488 | ||
162 | === modified file 'mojo/phase.py' | |||
163 | --- mojo/phase.py 2018-01-29 11:51:05 +0000 | |||
164 | +++ mojo/phase.py 2018-02-05 16:24:42 +0000 | |||
165 | @@ -302,6 +302,8 @@ | |||
166 | 302 | config = workspace.spec.get_config(self.config_base, stage) | 302 | config = workspace.spec.get_config(self.config_base, stage) |
167 | 303 | cmd = [mojovol, '--config', config] | 303 | cmd = [mojovol, '--config', config] |
168 | 304 | output = subprocess.check_output(cmd) | 304 | output = subprocess.check_output(cmd) |
169 | 305 | if six.PY3: | ||
170 | 306 | output = output.decode('utf-8') | ||
171 | 305 | logging.info(output) | 307 | logging.info(output) |
172 | 306 | 308 | ||
173 | 307 | 309 | ||
174 | @@ -396,10 +398,14 @@ | |||
175 | 396 | logging.error("Running exec-on-failure {}".format(exec_on_failure_script)) | 398 | logging.error("Running exec-on-failure {}".format(exec_on_failure_script)) |
176 | 397 | command = env_vars + [exec_on_failure_script] | 399 | command = env_vars + [exec_on_failure_script] |
177 | 398 | try: | 400 | try: |
179 | 399 | logging.error(subprocess.check_output(command, stderr=subprocess.STDOUT)) | 401 | output = subprocess.check_output( |
180 | 402 | command, stderr=subprocess.STDOUT) | ||
181 | 403 | if six.PY3: | ||
182 | 404 | output = output.decode('utf-8') | ||
183 | 405 | logging.error(output) | ||
184 | 400 | except subprocess.CalledProcessError as e: | 406 | except subprocess.CalledProcessError as e: |
185 | 401 | logging.error("There was an error running exec-on-failure") | 407 | logging.error("There was an error running exec-on-failure") |
187 | 402 | logging.error(e.output) | 408 | logging.error(e) |
188 | 403 | except ConfigNotFoundException: | 409 | except ConfigNotFoundException: |
189 | 404 | logging.debug("No exec-on-failure config found, see https://mojo.canonical.com/readme.html#exec-on-failure " | 410 | logging.debug("No exec-on-failure config found, see https://mojo.canonical.com/readme.html#exec-on-failure " |
190 | 405 | "for more details") | 411 | "for more details") |
191 | @@ -718,6 +724,8 @@ | |||
192 | 718 | subprocess.call(cmd) | 724 | subprocess.call(cmd) |
193 | 719 | else: | 725 | else: |
194 | 720 | diff = subprocess.check_output(cmd) | 726 | diff = subprocess.check_output(cmd) |
195 | 727 | if six.PY3: | ||
196 | 728 | diff = diff.decode('utf-8') | ||
197 | 721 | diff_processor(diff) | 729 | diff_processor(diff) |
198 | 722 | 730 | ||
199 | 723 | def run(self, project, workspace, stage, auto_secrets=True): | 731 | def run(self, project, workspace, stage, auto_secrets=True): |
200 | @@ -821,6 +829,8 @@ | |||
201 | 821 | failed_unit.replace("/", "-"),)] | 829 | failed_unit.replace("/", "-"),)] |
202 | 822 | with chdir(workspace.repo_dir): | 830 | with chdir(workspace.repo_dir): |
203 | 823 | failure = subprocess.check_output(cmd) | 831 | failure = subprocess.check_output(cmd) |
204 | 832 | if six.PY3: | ||
205 | 833 | failure = failure.decode('utf-8') | ||
206 | 824 | logging.error(failure) | 834 | logging.error(failure) |
207 | 825 | # Show juju status | 835 | # Show juju status |
208 | 826 | juju_status = mojo.juju.Status(environment=juju_env) | 836 | juju_status = mojo.juju.Status(environment=juju_env) |
209 | @@ -965,7 +975,7 @@ | |||
210 | 965 | auto_secrets=auto_secrets, gather_debug_logs=False) | 975 | auto_secrets=auto_secrets, gather_debug_logs=False) |
211 | 966 | except ScriptPhaseException as e: | 976 | except ScriptPhaseException as e: |
212 | 967 | if i < retry: | 977 | if i < retry: |
214 | 968 | logging.warning(e.output) | 978 | logging.warning(e) |
215 | 969 | logging.warning( | 979 | logging.warning( |
216 | 970 | "Error: verify script exited with status {} " | 980 | "Error: verify script exited with status {} " |
217 | 971 | "(attempt {} of {}); sleeping for {}s".format( | 981 | "(attempt {} of {}); sleeping for {}s".format( |
+1