Skip to content

Commit

Permalink
Add drivetrain tests
Browse files Browse the repository at this point in the history
Change-Id: I6dc5dde5a9d2e1c5be3ef9e932e3ae725f900c00
  • Loading branch information
Oleksii Zhurba committed Jun 26, 2018
1 parent e592ed1 commit a25984b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cvp_checks/global_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ test_mtu:
"skipped_ifaces": ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb"]}
# mask for interfaces to skip

drivetrain_version: ''

# ntp test setting
# this test may skip specific node (use fqdn)
test_ntp_sync:
Expand Down
91 changes: 91 additions & 0 deletions cvp_checks/tests/test_drivetrain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from jenkinsapi.jenkins import Jenkins
from xml.dom import minidom
from cvp_checks import utils
import json
import pytest


def test_drivetrain_services_replicas(local_salt_client):
salt_output = local_salt_client.cmd(
'I@docker:host and not I@prometheus:server and not I@kubernetes:*',
'cmd.run',
['docker service ls'],
expr_form='compound')
wrong_items = []
for line in salt_output[salt_output.keys()[0]].split('\n'):
if line[line.find('/') - 1] != line[line.find('/') + 1] \
and 'replicated' in line:
wrong_items.append(line)
assert len(wrong_items) == 0, \
'''Some DriveTrain services doesn't have expected number of replicas:
{}'''.format(json.dumps(wrong_items, indent=4))


def test_drivetrain_components_and_versions(local_salt_client):
config = utils.get_configuration()
version = config['drivetrain_version'] or []
if not version or version == '':
pytest.skip("drivetrain_version is not defined. Skipping")
salt_output = local_salt_client.cmd(
'I@docker:host and not I@prometheus:server and not I@kubernetes:*',
'cmd.run',
['docker service ls'],
expr_form='compound')
not_found_services = ['gerrit_db', 'gerrit_server', 'jenkins_master',
'jenkins_slave01', 'jenkins_slave02',
'jenkins_slave03', 'ldap_admin', 'ldap_server']
version_mismatch = []
for line in salt_output[salt_output.keys()[0]].split('\n'):
for service in not_found_services:
if service in line:
not_found_services.remove(service)
if version != line.split()[4].split(':')[1]:
version_mismatch.append("{0}: expected "
"version is {1}, actual - {2}".format(service,version,
line.split()[4].split(':')[1]))
continue
assert len(not_found_services) == 0, \
'''Some DriveTrain components are not found:
{}'''.format(json.dumps(not_found_services, indent=4))
assert len(version_mismatch) == 0, \
'''Version mismatch found:
{}'''.format(json.dumps(version_mismatch, indent=4))


def test_jenkins_jobs_branch(local_salt_client):
config = utils.get_configuration()
expected_version = config['drivetrain_version'] or []
if not expected_version or expected_version == '':
pytest.skip("drivetrain_version is not defined. Skipping")
jenkins_password = local_salt_client.cmd(
'jenkins:client',
'pillar.get',
['_param:openldap_admin_password'],
expr_form='pillar').values()[0]
jenkins_port = local_salt_client.cmd(
'I@jenkins:client and not I@salt:master',
'pillar.get',
['_param:haproxy_jenkins_bind_port'],
expr_form='compound').values()[0]
jenkins_address = local_salt_client.cmd(
'I@jenkins:client and not I@salt:master',
'pillar.get',
['_param:haproxy_jenkins_bind_host'],
expr_form='compound').values()[0]
version_mismatch = []
jenkins_url = 'http://{0}:{1}'.format(jenkins_address,jenkins_port)
server = Jenkins(jenkins_url, username='admin', password=jenkins_password)
for job_name, job_instance in server.get_jobs():
job_config = job_instance.get_config()
xml_data = minidom.parseString(job_config)
BranchSpec = xml_data.getElementsByTagName('hudson.plugins.git.BranchSpec')
if BranchSpec:
actual_version = BranchSpec[0].getElementsByTagName('name')[0].childNodes[0].data
if actual_version != expected_version and 'master' not in actual_version:
version_mismatch.append("Job {0} has {1} branch."
"Expected {2}".format(job_instance.name,
actual_version,
expected_version))
assert len(version_mismatch) == 0, \
'''Some DriveTrain jobs have version/branch mismatch:
{}'''.format(json.dumps(version_mismatch, indent=4))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest==3.0.6
requests
flake8
PyYAML
jenkinsapi

0 comments on commit a25984b

Please sign in to comment.