Merge lp:~1chb1n/ubuntu-openstack-ci/nova-instances-summarize into lp:ubuntu-openstack-ci

Proposed by Ryan Beisner
Status: Merged
Merged at revision: 63
Proposed branch: lp:~1chb1n/ubuntu-openstack-ci/nova-instances-summarize
Merge into: lp:ubuntu-openstack-ci
Diff against target: 217 lines (+147/-5)
5 files modified
common/osci_utils.py (+28/-0)
job-parts/deploy_with_deployer.sh (+3/-0)
job-parts/nova_instances_summarize.py (+97/-0)
job-parts/osci_job_common.sh (+13/-5)
tox.ini (+6/-0)
To merge this branch: bzr merge lp:~1chb1n/ubuntu-openstack-ci/nova-instances-summarize
Reviewer Review Type Date Requested Status
Ryan Beisner (community) Approve
Review via email: mp+245883@code.launchpad.net

Description of the change

* Add nova instance summary collector for deployment and amulet tests, replacing 'nova list' dump.
* Start creating deploy test tempest summary file for SKIPs/FAILs.
* Add tox.ini for flake8, regarding lint checks on uosci itself.
* Lint and misc cleanup.

To post a comment you must log in.
Revision history for this message
Ryan Beisner (1chb1n) wrote :

Testing in osci-staging enviro @ http://10.245.162.96:8080/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #629 lp:ubuntu-openstack-ci for 1chb1n mp245883
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/629/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #600 lp:ubuntu-openstack-ci for 1chb1n mp245883
    LINT FAIL: lint-test failed

LINT Results (max last 2 lines):
  ./common/osci_utils.py:288:80: E501 line too long (80 > 79 characters)
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9693926/
Build: http://10.245.162.77:8080/job/charm_lint_check/600/

67. By Ryan Beisner

update nova instance summarizer

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #631 lp:ubuntu-openstack-ci for 1chb1n mp245883
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/631/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #602 lp:ubuntu-openstack-ci for 1chb1n mp245883
    LINT FAIL: lint-test failed

LINT Results (max last 2 lines):
  ./common/osci_utils.py:288:80: E501 line too long (80 > 79 characters)
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9695606/
Build: http://10.245.162.77:8080/job/charm_lint_check/602/

68. By Ryan Beisner

start creating tempest summaries in deploy test

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #608 lp:ubuntu-openstack-ci for 1chb1n mp245883
    LINT FAIL: lint-test failed

LINT Results (max last 2 lines):
  ./common/osci_utils.py:288:80: E501 line too long (80 > 79 characters)
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9699028/
Build: http://10.245.162.77:8080/job/charm_lint_check/608/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #637 lp:ubuntu-openstack-ci for 1chb1n mp245883
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/637/

69. By Ryan Beisner

cleanup

Revision history for this message
Ryan Beisner (1chb1n) wrote :

tests complete, go.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common/osci_utils.py'
2--- common/osci_utils.py 2015-01-07 19:32:26 +0000
3+++ common/osci_utils.py 2015-01-09 20:10:09 +0000
4@@ -89,6 +89,18 @@
5 return False
6
7
8+def juju_stat():
9+ '''Get juju status, return dict data
10+ '''
11+ try:
12+ j_stat = yaml.load(subprocess.check_output(['juju', 'status']))
13+ except subprocess.CalledProcessError:
14+ logging.warning(' ! Juju status attempt returned non-zero, '
15+ 'most likely no juju enviro bootstrapped.')
16+ j_stat = {}
17+ return j_stat
18+
19+
20 def get_num_units(yaml_data, outer, service):
21 '''Return num_units from service in yaml data from juju bundle file
22
23@@ -103,6 +115,22 @@
24 return yaml_data[outer]['services'][service]['num_units']
25
26
27+def dict_unicode_to_str(ddata):
28+ '''Convert elements in a dictionary from unicode to string utf8
29+
30+ :ddata: dictionary data
31+ '''
32+ if isinstance(ddata, dict):
33+ return {dict_unicode_to_str(key): dict_unicode_to_str(value)
34+ for key, value in ddata.iteritems()}
35+ elif isinstance(ddata, unicode):
36+ return ddata.encode('utf-8')
37+ elif isinstance(ddata, list):
38+ return [dict_unicode_to_str(element) for element in ddata]
39+ else:
40+ return ddata
41+
42+
43 def recursive_dict_key_search(data, key):
44 '''Recursively look for key match in dictionaries, return value.
45
46
47=== modified file 'job-parts/deploy_with_deployer.sh'
48--- job-parts/deploy_with_deployer.sh 2014-12-06 06:51:33 +0000
49+++ job-parts/deploy_with_deployer.sh 2015-01-09 20:10:09 +0000
50@@ -47,6 +47,9 @@
51
52 # Run tempest smoke tests
53 f_openstack_run_tempest_smoke
54+
55+ # Pull summary (fails / skips only)
56+ f_openstack_tempest_summarize
57 else
58 echo " ! Juju deployment failed."
59 echo " ! Skipping tempest."
60
61=== added file 'job-parts/nova_instances_summarize.py'
62--- job-parts/nova_instances_summarize.py 1970-01-01 00:00:00 +0000
63+++ job-parts/nova_instances_summarize.py 2015-01-09 20:10:09 +0000
64@@ -0,0 +1,97 @@
65+#!/usr/bin/python
66+'''Gathers info about nova instances, filtered by instance name based on
67+local default juju environment name, and writes a summary yaml text file.
68+'''
69+
70+import os
71+import sys
72+import yaml
73+import logging
74+import tempfile
75+from novaclient import client as nv_client
76+sys.path.insert(1, os.path.join(sys.path[0], '..'))
77+from common import osci_utils
78+
79+# Set default logging level
80+logging.basicConfig(level=logging.INFO)
81+
82+try:
83+ WORKSPACE = os.environ['WORKSPACE']
84+except KeyError:
85+ WORKSPACE = tempfile.mkdtemp()
86+
87+try:
88+ BUILD_NUMBER = os.environ['BUILD_NUMBER']
89+except KeyError:
90+ BUILD_NUMBER = '000'
91+
92+
93+def summarize_nova_instances(creds, name_substr=''):
94+ '''Gather info about nova instances, optionally filtered by
95+ instance name substring, and return summary data in a dictionary.
96+ '''
97+ nova = nv_client.Client('2', **creds[1])
98+ servers = nova.servers.list()
99+ nova_ddata = {}
100+ logging.info('Instance name filter substring: {}'.format(name_substr))
101+ inst_count = 0
102+ for server in servers:
103+ if name_substr in str(server.name):
104+ inst_count += 1
105+ image = nova.images.get(server.image['id'])
106+ nova_ddata[str(server.id)] = {
107+ 'inst-name': str(server.name),
108+ 'inst-date': str(server.created),
109+ 'inst-stat': str(server.status),
110+ 'inst-flav': str(server.flavor['id']),
111+ 'img-id': str(server.image['id']),
112+ 'img-name': str(image.name),
113+ 'img-date': str(image.created),
114+ 'net': osci_utils.dict_unicode_to_str(server.addresses)
115+ }
116+# 'net2': osci_utils.dict_unicode_to_str(server.networks)
117+
118+ logging.info('Instance count (all): {}'.format(len(servers)))
119+ logging.info('Instance count (filtered): {}'.format(inst_count))
120+ return nova_ddata
121+
122+
123+def write_instance_summary_file(inst_summs):
124+ '''Write out instance summary data to yaml txt file
125+ '''
126+ out_file = 'nova-instance-summary.{}'.format(BUILD_NUMBER)
127+ target = os.path.join(WORKSPACE, out_file)
128+ logging.info(' + Creating nova instance summary file: {}'.format(target))
129+ osci_utils.write_yaml(inst_summs, target)
130+
131+ # Quick confirmation of file success
132+ test_file = osci_utils.read_yaml(target)
133+ if len(inst_summs) != len(test_file):
134+ msg = ' ! Instance summary file data may not be complete.'
135+ return msg
136+
137+
138+def main():
139+ '''Gather nova info about current nova instances, create summary file.
140+ '''
141+
142+ print 'Starting nova_instances_summarize.'
143+ logging.info('Workspace dir: {}'.format(WORKSPACE))
144+ creds = osci_utils.get_os_creds()
145+
146+ # get juju environment name, to be used to filter instance names
147+ j_data = osci_utils.juju_stat()
148+ j_env_name = j_data['environment']
149+
150+ # get summary of matching nova instances
151+ inst_summs = summarize_nova_instances(creds, name_substr=j_env_name)
152+ logging.debug('instance summary data: \n{}'.format(
153+ yaml.dump(inst_summs, default_flow_style=False)))
154+
155+ # write summary to file in workspace
156+ ret = write_instance_summary_file(inst_summs)
157+ if ret:
158+ raise ValueError(ret)
159+
160+if __name__ == '__main__':
161+ main()
162
163=== modified file 'job-parts/osci_job_common.sh'
164--- job-parts/osci_job_common.sh 2014-12-15 22:21:52 +0000
165+++ job-parts/osci_job_common.sh 2015-01-09 20:10:09 +0000
166@@ -157,7 +157,8 @@
167 . $JENKINS_HOME/novarc
168 ${OSCI_ROOT}/job-parts/pull_juju_logs.py || true
169 ${OSCI_ROOT}/job-parts/collect_charm_revno_info.sh || true
170- nova list &> $WORKSPACE/nova-list.$BUILD_NUMBER || true
171+ ${OSCI_ROOT}/job-parts/nova_instances_summarize.py || true
172+# nova list &> $WORKSPACE/nova-list.$BUILD_NUMBER || true
173 juju stat &> $WORKSPACE/juju-stat.$BUILD_NUMBER || true
174 }
175
176@@ -259,12 +260,12 @@
177 else
178 # Kick off tempest
179 (cd $OPENSTACK_CHARM_TESTING_ROOT/tempest && ./run_tempest.sh -N --smoke) 2>&1 |\
180- tee $WORKSPACE/tempest.$BUILD_NUMBER
181- if [[ -n "$(grep 'failures=' $WORKSPACE/tempest.$BUILD_NUMBER)" ]]; then
182+ tee $WORKSPACE/tempest-allresults.$BUILD_NUMBER
183+ if [[ -n "$(grep 'failures=' $WORKSPACE/tempest-allresults.$BUILD_NUMBER)" ]]; then
184 echo " ! One or more tempest smoke tests failed."
185 touch $WORKSPACE/fyi-${test:0:4}.tempest.bad
186- elif [[ -z "$(grep 'failures=' $WORKSPACE/tempest.$BUILD_NUMBER)" ]] &&\
187- [[ -n "$(grep 'tempest.scenario.test' $WORKSPACE/tempest.$BUILD_NUMBER)" ]] ; then
188+ elif [[ -z "$(grep 'failures=' $WORKSPACE/tempest-allresults.$BUILD_NUMBER)" ]] &&\
189+ [[ -n "$(grep 'tempest.scenario.test' $WORKSPACE/tempest-allresults.$BUILD_NUMBER)" ]] ; then
190 echo " . All tempest smoke tests passed!"
191 touch $WORKSPACE/fyi-${test:0:4}.tempest.ok
192 else
193@@ -274,6 +275,13 @@
194 }
195
196
197+function f_openstack_tempest_summarize() {
198+ if [[ -f $WORKSPACE/tempest-allresults.$BUILD_NUMBER ]]; then
199+ egrep 'FAIL|^Ran|====|SKIP' $WORKSPACE/tempest-allresults.$BUILD_NUMBER > $WORKSPACE/tempest-summary.$BUILD_NUMBER || true
200+ fi
201+}
202+
203+
204 function f_openstack_cli_basic_check() {
205 # Perform basic command line checks against the cloud
206 echo "Confirming basic CLI functionality and authentication..."
207
208=== added file 'tox.ini'
209--- tox.ini 1970-01-01 00:00:00 +0000
210+++ tox.ini 2015-01-09 20:10:09 +0000
211@@ -0,0 +1,6 @@
212+[flake8]
213+# The following checks should be re-enabled in the future
214+# for python3 syntax correctness and sanity.
215+#
216+ignore = H233,H301,H302,H305,H306,H402,H403,H405,H904
217+#show-source = True

Subscribers

People subscribed via source and target branches