summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnastasia Kuznetsova <akuznetsova@mirantis.com>2016-08-29 14:47:15 +0300
committerAnastasia Kuznetsova <akuznetsova@mirantis.com>2016-08-30 19:38:05 +0300
commitfd00e5d2862ec584eb501c6faa4c662b38e2d3eb (patch)
tree316414632cfeb6c4d0c433806d3f723fcd89b2e9
parentb3fe456381c1b14584b4bcc9b6f6260adb092dd6 (diff)
Tech dept: fix comments from previous commit with new tests
Notes
Notes (review): Verified+1: murano-ci-cd CI <murano-ci-cd-bot@mirantis.com> Code-Review+2: Sergey Kraynev <skraynev@mirantis.com> Code-Review+2: Alexey Khivin <akhivin@gmail.com> Workflow+1: Alexey Khivin <akhivin@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 31 Aug 2016 13:39:03 +0000 Reviewed-on: https://review.openstack.org/362043 Project: openstack/ci-cd-pipeline-app-murano Branch: refs/heads/master
-rwxr-xr-xtests/base.py41
-rw-r--r--tests/test_cicd_apps_flow.py2
-rw-r--r--tox.ini3
3 files changed, 24 insertions, 22 deletions
diff --git a/tests/base.py b/tests/base.py
index 2041840..2775fa6 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -31,7 +31,7 @@ import muranoclient.common.exceptions as exceptions
31 31
32import clients 32import clients
33 33
34ARTIFACTS_DIR = os.environ.get('ARTIFACTS_DIR', 'logs') 34ARTIFACTS_DIR = os.environ.get('ARTIFACTS_DIR', 'artifacts')
35 35
36LOG = logging.getLogger(__name__) 36LOG = logging.getLogger(__name__)
37LOG.setLevel(logging.DEBUG) 37LOG.setLevel(logging.DEBUG)
@@ -60,6 +60,8 @@ def str2bool(name, default):
60 value = os.environ.get(name, '') 60 value = os.environ.get(name, '')
61 return _boolean_states.get(value.lower(), default) 61 return _boolean_states.get(value.lower(), default)
62 62
63TIMEOUT_DELAY = 30
64
63 65
64class MuranoTestsBase(testtools.TestCase, clients.ClientsBase): 66class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
65 67
@@ -273,7 +275,6 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
273 fips = self.get_services_fips(environment) 275 fips = self.get_services_fips(environment)
274 logs_dir = "{0}/{1}".format(ARTIFACTS_DIR, environment.name) 276 logs_dir = "{0}/{1}".format(ARTIFACTS_DIR, environment.name)
275 os.makedirs(logs_dir) 277 os.makedirs(logs_dir)
276 self.files.append(logs_dir)
277 for service, fip in fips.iteritems(): 278 for service, fip in fips.iteritems():
278 try: 279 try:
279 ssh = paramiko.SSHClient() 280 ssh = paramiko.SSHClient()
@@ -312,7 +313,7 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
312 'Environment has incorrect status "{0}"'.format(status) 313 'Environment has incorrect status "{0}"'.format(status)
313 ) 314 )
314 315
315 time.sleep(30) 316 time.sleep(TIMEOUT_DELAY)
316 LOG.debug('Environment "{0}" is ready'.format(self.get_env(env).name)) 317 LOG.debug('Environment "{0}" is ready'.format(self.get_env(env).name))
317 return self.get_env(env).manager.get(env.id) 318 return self.get_env(env).manager.get(env.id)
318 319
@@ -526,7 +527,7 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
526 return patch['number'] 527 return patch['number']
527 528
528 def merge_commit(self, gerrit_ip, gerrit_host, project, commit_msg): 529 def merge_commit(self, gerrit_ip, gerrit_host, project, commit_msg):
529 changeid = self.get_last_open_patch( 530 patch_num = self.get_last_open_patch(
530 gerrit_ip=gerrit_ip, 531 gerrit_ip=gerrit_ip,
531 gerrit_host=gerrit_host, 532 gerrit_host=gerrit_host,
532 project=project, 533 project=project,
@@ -536,7 +537,7 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
536 cmd = ( 537 cmd = (
537 'gerrit review --project {project} --verified +2 ' 538 'gerrit review --project {project} --verified +2 '
538 '--code-review +2 --label Workflow=+1 ' 539 '--code-review +2 --label Workflow=+1 '
539 '--submit {id},1'.format(project=project, id=changeid) 540 '--submit {id},1'.format(project=project, id=patch_num)
540 ) 541 )
541 cmd = self._gerrit_cmd(gerrit_host, cmd) 542 cmd = self._gerrit_cmd(gerrit_host, cmd)
542 543
@@ -568,37 +569,41 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
568 cmd=cmd 569 cmd=cmd
569 ) 570 )
570 571
571 def get_jenkins_jobs(self, ip):
572 server = jenkins.Jenkins('http://{0}:8080'.format(ip))
573
574 return [job['name'] for job in server.get_all_jobs()]
575
576 def wait_for(self, func, expected, debug_msg, fail_msg, timeout, **kwargs): 572 def wait_for(self, func, expected, debug_msg, fail_msg, timeout, **kwargs):
577 LOG.debug(debug_msg)
578 start_time = time.time()
579
580 current = func(**kwargs)
581
582 def check(exp, cur): 573 def check(exp, cur):
583 if isinstance(cur, list) or isinstance(cur, str): 574 if isinstance(cur, list) or isinstance(cur, str):
584 return exp not in cur 575 return exp not in cur
585 else: 576 else:
586 return exp != cur 577 return exp != cur
587 578
579 LOG.debug(debug_msg)
580 start_time = time.time()
581
582 current = func(**kwargs)
583
588 while check(expected, current): 584 while check(expected, current):
589 current = func(**kwargs) 585 current = func(**kwargs)
590 586
591 if time.time() - start_time > timeout: 587 if time.time() - start_time > timeout:
592 self.fail("Time is out. {0}".format(fail_msg)) 588 self.fail("Time is out. {0}".format(fail_msg))
593 time.sleep(30) 589 time.sleep(TIMEOUT_DELAY)
594 LOG.debug('Expected result has been achieved.') 590 LOG.debug('Expected result has been achieved.')
595 591
596 def get_last_build_number(self, ip, user, password, job_name, build_type): 592 @staticmethod
597 server = jenkins.Jenkins( 593 def _connect_jenkins_server(ip, user=None, password=None):
594 return jenkins.Jenkins(
598 'http://{0}:8080'.format(ip), 595 'http://{0}:8080'.format(ip),
599 username=user, 596 username=user,
600 password=password 597 password=password
601 ) 598 )
599
600 def get_jenkins_jobs(self, ip):
601 server = self._connect_jenkins_server(ip)
602
603 return [job['name'] for job in server.get_all_jobs()]
604
605 def get_last_build_number(self, ip, user, password, job_name, build_type):
606 server = self._connect_jenkins_server(ip, user, password)
602 # If there are no builds of desired type get_job_info returns None and 607 # If there are no builds of desired type get_job_info returns None and
603 # it is not possible to get number, in this case this function returns 608 # it is not possible to get number, in this case this function returns
604 # None too and it means that there are no builds yet 609 # None too and it means that there are no builds yet
diff --git a/tests/test_cicd_apps_flow.py b/tests/test_cicd_apps_flow.py
index 9f8dc17..403512d 100644
--- a/tests/test_cicd_apps_flow.py
+++ b/tests/test_cicd_apps_flow.py
@@ -210,7 +210,7 @@ class MuranoCiCdFlowTest(base.MuranoTestsBase):
210 new_job 210 new_job
211 ) 211 )
212 212
213 # Making commit to project-config 213 # Make commit to project-config
214 214
215 self.make_commit( 215 self.make_commit(
216 repo=project_config_location, 216 repo=project_config_location,
diff --git a/tox.ini b/tox.ini
index dde079b..18d452c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -22,12 +22,9 @@ distribute = false
22commands = {posargs:} 22commands = {posargs:}
23 23
24[testenv:deploy_cicd_apps] 24[testenv:deploy_cicd_apps]
25# FIXME!
26commands = python -m unittest tests.test_cicd_apps.MuranoCiCdTest.test_deploy_cicd 25commands = python -m unittest tests.test_cicd_apps.MuranoCiCdTest.test_deploy_cicd
27#commands = python setup.py testr --testr-args='{posargs}'
28 26
29[testenv:run_cicd_flow] 27[testenv:run_cicd_flow]
30# FIXME!
31commands = python -m unittest tests.test_cicd_apps_flow.MuranoCiCdFlowTest.test_run_cicd_flow 28commands = python -m unittest tests.test_cicd_apps_flow.MuranoCiCdFlowTest.test_run_cicd_flow
32 29
33[testenv:hacking] 30[testenv:hacking]