Merge "Functional test for agent"

This commit is contained in:
Jenkins 2017-02-09 06:35:56 +00:00 committed by Gerrit Code Review
commit 46d1df0adf

@ -11,6 +11,7 @@
# under the License. # under the License.
import hashlib import hashlib
import json
from openstackclient.tests.functional import base from openstackclient.tests.functional import base
@ -18,60 +19,178 @@ from openstackclient.tests.functional import base
class ComputeAgentTests(base.TestCase): class ComputeAgentTests(base.TestCase):
"""Functional tests for compute agent.""" """Functional tests for compute agent."""
ID = None # Generate two different md5hash
MD5HASH = hashlib.md5().hexdigest() MD5HASH1 = hashlib.md5()
URL = "http://localhost" MD5HASH1.update('agent_1')
VER = "v1" MD5HASH1 = MD5HASH1.hexdigest()
OS = "TEST_OS" MD5HASH2 = hashlib.md5()
ARCH = "x86_64" MD5HASH2.update('agent_2')
HYPER = "kvm" MD5HASH2 = MD5HASH2.hexdigest()
HEADERS = ['agent_id', 'md5hash'] def test_compute_agent_delete(self):
FIELDS = ['agent_id', 'md5hash'] """Test compute agent create, delete multiple"""
os1 = "os_1"
arch1 = "x86_64"
ver1 = "v1"
url1 = "http://localhost"
md5hash1 = self.MD5HASH1
hyper1 = "kvm"
cmd1 = ' '.join((os1, arch1, ver1, url1, md5hash1, hyper1))
@classmethod cmd_output = json.loads(self.openstack(
def setUpClass(cls): 'compute agent create -f json ' +
opts = cls.get_opts(cls.HEADERS) cmd1
raw_output = cls.openstack('compute agent create ' + ))
cls.OS + ' ' + cls.ARCH + ' ' + agent_id1 = str(cmd_output["agent_id"])
cls.VER + ' ' + cls.URL + ' ' +
cls.MD5HASH + ' ' + cls.HYPER + ' ' +
opts)
# Get agent id because agent can only be deleted by ID os2 = "os_2"
output_list = raw_output.split('\n', 1) arch2 = "x86"
cls.ID = output_list[0] ver2 = "v2"
url2 = "http://openstack"
md5hash2 = self.MD5HASH2
hyper2 = "xen"
cmd2 = ' '.join((os2, arch2, ver2, url2, md5hash2, hyper2))
cls.assertOutput(cls.MD5HASH + '\n', output_list[1]) cmd_output = json.loads(self.openstack(
'compute agent create -f json ' +
cmd2
))
agent_id2 = str(cmd_output["agent_id"])
@classmethod # Test compute agent delete
def tearDownClass(cls): del_output = self.openstack(
raw_output = cls.openstack('compute agent delete ' + cls.ID) 'compute agent delete ' +
cls.assertOutput('', raw_output) agent_id1 + ' ' + agent_id2
)
self.assertOutput('', del_output)
def test_agent_list(self): def test_compute_agent_list(self):
raw_output = self.openstack('compute agent list') """Test compute agent create and list"""
self.assertIn(self.ID, raw_output) os1 = "os_1"
self.assertIn(self.OS, raw_output) arch1 = "x86_64"
self.assertIn(self.ARCH, raw_output) ver1 = "v1"
self.assertIn(self.VER, raw_output) url1 = "http://localhost"
self.assertIn(self.URL, raw_output) md5hash1 = self.MD5HASH1
self.assertIn(self.MD5HASH, raw_output) hyper1 = "kvm"
self.assertIn(self.HYPER, raw_output) cmd1 = ' '.join((os1, arch1, ver1, url1, md5hash1, hyper1))
def test_agent_set(self): cmd_output = json.loads(self.openstack(
ver = 'v2' 'compute agent create -f json ' +
url = "http://openstack" cmd1
md5hash = hashlib.md5().hexdigest() ))
agent_id1 = str(cmd_output["agent_id"])
self.addCleanup(self.openstack, 'compute agent delete ' + agent_id1)
self.openstack('compute agent set ' os2 = "os_2"
+ self.ID arch2 = "x86"
+ ' --agent-version ' + ver ver2 = "v2"
+ ' --url ' + url url2 = "http://openstack"
+ ' --md5hash ' + md5hash) md5hash2 = self.MD5HASH2
hyper2 = "xen"
cmd2 = ' '.join((os2, arch2, ver2, url2, md5hash2, hyper2))
raw_output = self.openstack('compute agent list') cmd_output = json.loads(self.openstack(
self.assertIn(self.ID, raw_output) 'compute agent create -f json ' +
self.assertIn(ver, raw_output) cmd2
self.assertIn(url, raw_output) ))
self.assertIn(md5hash, raw_output) agent_id2 = str(cmd_output["agent_id"])
self.addCleanup(self.openstack, 'compute agent delete ' + agent_id2)
# Test compute agent list
cmd_output = json.loads(self.openstack(
'compute agent list -f json'
))
hypervisors = [x["Hypervisor"] for x in cmd_output]
self.assertIn(hyper1, hypervisors)
self.assertIn(hyper2, hypervisors)
os = [x['OS'] for x in cmd_output]
self.assertIn(os1, os)
self.assertIn(os2, os)
archs = [x['Architecture'] for x in cmd_output]
self.assertIn(arch1, archs)
self.assertIn(arch2, archs)
versions = [x['Version'] for x in cmd_output]
self.assertIn(ver1, versions)
self.assertIn(ver2, versions)
md5hashes = [x['Md5Hash'] for x in cmd_output]
self.assertIn(md5hash1, md5hashes)
self.assertIn(md5hash2, md5hashes)
urls = [x['URL'] for x in cmd_output]
self.assertIn(url1, urls)
self.assertIn(url2, urls)
# Test compute agent list --hypervisor
cmd_output = json.loads(self.openstack(
'compute agent list -f json ' +
'--hypervisor kvm'
))
hypervisors = [x["Hypervisor"] for x in cmd_output]
self.assertIn(hyper1, hypervisors)
self.assertNotIn(hyper2, hypervisors)
os = [x['OS'] for x in cmd_output]
self.assertIn(os1, os)
self.assertNotIn(os2, os)
archs = [x['Architecture'] for x in cmd_output]
self.assertIn(arch1, archs)
self.assertNotIn(arch2, archs)
versions = [x['Version'] for x in cmd_output]
self.assertIn(ver1, versions)
self.assertNotIn(ver2, versions)
md5hashes = [x['Md5Hash'] for x in cmd_output]
self.assertIn(md5hash1, md5hashes)
self.assertNotIn(md5hash2, md5hashes)
urls = [x['URL'] for x in cmd_output]
self.assertIn(url1, urls)
self.assertNotIn(url2, urls)
def test_compute_agent_set(self):
"""Test compute agent set"""
os1 = "os_1"
arch1 = "x86_64"
ver1 = "v1"
ver2 = "v2"
url1 = "http://localhost"
url2 = "http://openstack"
md5hash1 = self.MD5HASH1
md5hash2 = self.MD5HASH2
hyper1 = "kvm"
cmd = ' '.join((os1, arch1, ver1, url1, md5hash1, hyper1))
cmd_output = json.loads(self.openstack(
'compute agent create -f json ' +
cmd
))
agent_id = str(cmd_output["agent_id"])
self.assertEqual(ver1, cmd_output["version"])
self.assertEqual(url1, cmd_output["url"])
self.assertEqual(md5hash1, cmd_output["md5hash"])
self.addCleanup(self.openstack, 'compute agent delete ' + agent_id)
raw_output = self.openstack(
'compute agent set ' +
agent_id + ' ' +
'--agent-version ' + ver2 + ' ' +
'--url ' + url2 + ' ' +
'--md5hash ' + md5hash2
)
self.assertOutput('', raw_output)
cmd_output = json.loads(self.openstack(
'compute agent list -f json'
))
self.assertEqual(ver2, cmd_output[0]["Version"])
self.assertEqual(url2, cmd_output[0]["URL"])
self.assertEqual(md5hash2, cmd_output[0]["Md5Hash"])