Common Dockerfile for CVP-Sanity and CVP-SPT
Related-Task: #PROD-26312(PROD:26312)
Change-Id: I457a8d5c6ff73d944518f6b0c2c568f8286728a9
diff --git a/test_set/cvp_spt/tests/__init__.py b/test_set/cvp_spt/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_set/cvp_spt/tests/__init__.py
diff --git a/test_set/cvp_spt/tests/conftest.py b/test_set/cvp_spt/tests/conftest.py
new file mode 100644
index 0000000..a0636ac
--- /dev/null
+++ b/test_set/cvp_spt/tests/conftest.py
@@ -0,0 +1 @@
+from cvp_spt.fixtures.base import *
diff --git a/test_set/cvp_spt/tests/test_glance.py b/test_set/cvp_spt/tests/test_glance.py
new file mode 100644
index 0000000..fd6681f
--- /dev/null
+++ b/test_set/cvp_spt/tests/test_glance.py
@@ -0,0 +1,54 @@
+import pytest
+import time
+import subprocess
+import cvp_spt.utils as utils
+
+
+@pytest.fixture
+def create_image():
+ line = 'echo "Executing dd on $(hostname -f)"; ' \
+ 'dd if=/dev/zero of=/tmp/image_mk_framework.dd bs=1M count=9000 ;' \
+ 'echo "Free space :" ; ' \
+ 'df -H / '
+
+ subprocess.call(line.split())
+ yield
+ # teardown
+ subprocess.call('rm /tmp/image_mk_framework.dd'.split())
+ subprocess.call('rm /tmp/image_mk_framework.download'.split())
+
+
+def test_speed_glance(create_image, openstack_clients, record_property):
+ """
+ Simplified Performance Tests Download / upload lance
+ 1. Step download image
+ 2. Step upload image
+ """
+ image = openstack_clients.image.images.create(
+ name="test_image",
+ disk_format='iso',
+ container_format='bare')
+
+ start_time = time.time()
+ openstack_clients.image.images.upload(
+ image.id,
+ image_data=open("/tmp/image_mk_framework.dd", 'rb'))
+ end_time = time.time()
+
+ speed_upload = 9000 / (end_time - start_time)
+
+ start_time = time.time()
+ with open("/tmp/image_mk_framework.download", 'wb') as image_file:
+ for item in openstack_clients.image.images.data(image.id):
+ image_file.write(item)
+ end_time = time.time()
+
+ speed_download = 9000 / (end_time - start_time)
+
+ openstack_clients.image.images.delete(image.id)
+ record_property("Upload", speed_upload)
+ record_property("Download", speed_download)
+
+ print "++++++++++++++++++++++++++++++++++++++++"
+ print 'upload - {} Mb/s'.format(speed_upload)
+ print 'download - {} Mb/s'.format(speed_download)
diff --git a/test_set/cvp_spt/tests/test_hw2hw.py b/test_set/cvp_spt/tests/test_hw2hw.py
new file mode 100644
index 0000000..629be42
--- /dev/null
+++ b/test_set/cvp_spt/tests/test_hw2hw.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+import itertools
+import re
+import os
+import yaml
+import requests
+from cvp_spt import utils
+from cvp_spt.utils import helpers
+from netaddr import IPNetwork, IPAddress
+
+
+def test_hw2hw (local_salt_client,hw_pair,record_property):
+ helpp = helpers.helpers(local_salt_client)
+ config = utils.get_configuration()
+ nodes = local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]),
+ fun='network.interfaces')
+ short_name = []
+ short_name.append(hw_pair[0].split('.')[0])
+ short_name.append(hw_pair[1].split('.')[0])
+ nets = config.get('networks').split(',')
+ local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]),
+ fun='cmd.run', param=['nohup iperf -s > file 2>&1 &'])
+ global_results = []
+ for net in nets:
+ for interf in nodes[hw_pair[0]]:
+ if 'inet' not in nodes[hw_pair[0]][interf].keys():
+ continue
+ ip = nodes[hw_pair[0]][interf]['inet'][0]['address']
+ if (IPAddress(ip) in IPNetwork(net)) and (nodes[hw_pair[0]][interf]['inet'][0]['broadcast']):
+ for interf2 in nodes[hw_pair[1]]:
+ if 'inet' not in nodes[hw_pair[1]][interf2].keys():
+ continue
+ ip2 = nodes[hw_pair[1]][interf2]['inet'][0]['address']
+ if (IPAddress(ip2) in IPNetwork(net)) and (nodes[hw_pair[1]][interf2]['inet'][0]['broadcast']):
+ print "Will IPERF between {0} and {1}".format(ip,ip2)
+ try:
+ res = helpp.start_iperf_between_hosts(global_results, hw_pair[0], hw_pair[1],
+ ip, ip2, net)
+ record_property("1-worst {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] < res[2] else res[2])
+ record_property("1-best {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] > res[2] else res[2])
+ record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3])
+ record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3])
+ print "Measurement between {} and {} " \
+ "has been finished".format(hw_pair[0],
+ hw_pair[1])
+ except Exception as e:
+ print "Failed for {0} {1}".format(
+ hw_pair[0], hw_pair[1])
+ print e
+ local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]),
+ fun='cmd.run', param=['killall -9 iperf'])
+ helpp.draw_table_with_results(global_results)
diff --git a/test_set/cvp_spt/tests/test_vm2vm.py b/test_set/cvp_spt/tests/test_vm2vm.py
new file mode 100644
index 0000000..9e1d5d7
--- /dev/null
+++ b/test_set/cvp_spt/tests/test_vm2vm.py
@@ -0,0 +1,103 @@
+import os
+import random
+import time
+import pytest
+from cvp_spt import utils
+from cvp_spt.utils import os_client
+from cvp_spt.utils import ssh
+
+
+def test_vm2vm (openstack_clients, pair, os_resources, record_property):
+ os_actions = os_client.OSCliActions(openstack_clients)
+ config = utils.get_configuration()
+ timeout = int(config.get('nova_timeout', 30))
+ try:
+ zone1 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[0]]
+ zone2 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[1]]
+ vm1 = os_actions.create_basic_server(os_resources['image_id'],
+ os_resources['flavor_id'],
+ os_resources['net1'],
+ '{0}:{1}'.format(zone1[0],pair[0]),
+ [os_resources['sec_group'].name],
+ os_resources['keypair'].name)
+
+ vm2 = os_actions.create_basic_server(os_resources['image_id'],
+ os_resources['flavor_id'],
+ os_resources['net1'],
+ '{0}:{1}'.format(zone1[0],pair[0]),
+ [os_resources['sec_group'].name],
+ os_resources['keypair'].name)
+
+ vm3 = os_actions.create_basic_server(os_resources['image_id'],
+ os_resources['flavor_id'],
+ os_resources['net1'],
+ '{0}:{1}'.format(zone2[0],pair[1]),
+ [os_resources['sec_group'].name],
+ os_resources['keypair'].name)
+
+ vm4 = os_actions.create_basic_server(os_resources['image_id'],
+ os_resources['flavor_id'],
+ os_resources['net2'],
+ '{0}:{1}'.format(zone2[0],pair[1]),
+ [os_resources['sec_group'].name],
+ os_resources['keypair'].name)
+
+ vm_info = []
+ vms = []
+ vms.extend([vm1,vm2,vm3,vm4])
+ fips = []
+ time.sleep(5)
+ for i in range(4):
+ fip = openstack_clients.compute.floating_ips.create(os_resources['ext_net']['name'])
+ fips.append(fip.id)
+ status = openstack_clients.compute.servers.get(vms[i]).status
+ if status != 'ACTIVE':
+ print "VM #{0} {1} is not ready. Status {2}".format(i,vms[i].id,status)
+ time.sleep(timeout)
+ status = openstack_clients.compute.servers.get(vms[i]).status
+ if status != 'ACTIVE':
+ raise Exception('VM is not ready')
+ vms[i].add_floating_ip(fip)
+ private_address = vms[i].addresses[vms[i].addresses.keys()[0]][0]['addr']
+ time.sleep(5)
+ try:
+ ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
+ except Exception as e:
+ print e
+ print "ssh.prepare_iperf was not successful, retry after {} sec".format(timeout)
+ time.sleep(timeout)
+ ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
+ vm_info.append({'vm': vms[i], 'fip': fip.ip, 'private_address': private_address})
+
+ transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', password='dd', private_key=os_resources['keypair'].private_key)
+
+ result1 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[1]['private_address']))
+ print ' '.join(result1.split()[-2::])
+ record_property("same {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result1.split()[-2::]))
+ result2 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[2]['private_address']))
+ print ' '.join(result2.split()[-2::])
+ record_property("diff host {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result2.split()[-2::]))
+ result3 = transport1.exec_command('iperf -c {} -P 10 | tail -n 1'.format(vm_info[2]['private_address']))
+ print ' '.join(result3.split()[-2::])
+ record_property("dif host 10 threads {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result3.split()[-2::]))
+ result4 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[2]['fip']))
+ print ' '.join(result4.split()[-2::])
+ record_property("diff host fip {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result4.split()[-2::]))
+ result5 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[3]['private_address']))
+ print ' '.join(result5.split()[-2::])
+ record_property("diff host, diff net {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result5.split()[-2::]))
+
+ print "Remove VMs"
+ for vm in vms:
+ openstack_clients.compute.servers.delete(vm)
+ print "Remove FIPs"
+ for fip in fips:
+ openstack_clients.compute.floating_ips.delete(fip)
+ except Exception as e:
+ print e
+ print "Something went wrong"
+ for vm in vms:
+ openstack_clients.compute.servers.delete(vm)
+ for fip in fips:
+ openstack_clients.compute.floating_ips.delete(fip)
+ pytest.fail("Something went wrong")