Merge "Functional test for agent"
This commit is contained in:
commit
46d1df0adf
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
from openstackclient.tests.functional import base
|
||||
|
||||
@ -18,60 +19,178 @@ from openstackclient.tests.functional import base
|
||||
class ComputeAgentTests(base.TestCase):
|
||||
"""Functional tests for compute agent."""
|
||||
|
||||
ID = None
|
||||
MD5HASH = hashlib.md5().hexdigest()
|
||||
URL = "http://localhost"
|
||||
VER = "v1"
|
||||
OS = "TEST_OS"
|
||||
ARCH = "x86_64"
|
||||
HYPER = "kvm"
|
||||
# Generate two different md5hash
|
||||
MD5HASH1 = hashlib.md5()
|
||||
MD5HASH1.update('agent_1')
|
||||
MD5HASH1 = MD5HASH1.hexdigest()
|
||||
MD5HASH2 = hashlib.md5()
|
||||
MD5HASH2.update('agent_2')
|
||||
MD5HASH2 = MD5HASH2.hexdigest()
|
||||
|
||||
HEADERS = ['agent_id', 'md5hash']
|
||||
FIELDS = ['agent_id', 'md5hash']
|
||||
def test_compute_agent_delete(self):
|
||||
"""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
|
||||
def setUpClass(cls):
|
||||
opts = cls.get_opts(cls.HEADERS)
|
||||
raw_output = cls.openstack('compute agent create ' +
|
||||
cls.OS + ' ' + cls.ARCH + ' ' +
|
||||
cls.VER + ' ' + cls.URL + ' ' +
|
||||
cls.MD5HASH + ' ' + cls.HYPER + ' ' +
|
||||
opts)
|
||||
cmd_output = json.loads(self.openstack(
|
||||
'compute agent create -f json ' +
|
||||
cmd1
|
||||
))
|
||||
agent_id1 = str(cmd_output["agent_id"])
|
||||
|
||||
# Get agent id because agent can only be deleted by ID
|
||||
output_list = raw_output.split('\n', 1)
|
||||
cls.ID = output_list[0]
|
||||
os2 = "os_2"
|
||||
arch2 = "x86"
|
||||
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
|
||||
def tearDownClass(cls):
|
||||
raw_output = cls.openstack('compute agent delete ' + cls.ID)
|
||||
cls.assertOutput('', raw_output)
|
||||
# Test compute agent delete
|
||||
del_output = self.openstack(
|
||||
'compute agent delete ' +
|
||||
agent_id1 + ' ' + agent_id2
|
||||
)
|
||||
self.assertOutput('', del_output)
|
||||
|
||||
def test_agent_list(self):
|
||||
raw_output = self.openstack('compute agent list')
|
||||
self.assertIn(self.ID, raw_output)
|
||||
self.assertIn(self.OS, raw_output)
|
||||
self.assertIn(self.ARCH, raw_output)
|
||||
self.assertIn(self.VER, raw_output)
|
||||
self.assertIn(self.URL, raw_output)
|
||||
self.assertIn(self.MD5HASH, raw_output)
|
||||
self.assertIn(self.HYPER, raw_output)
|
||||
def test_compute_agent_list(self):
|
||||
"""Test compute agent create and list"""
|
||||
os1 = "os_1"
|
||||
arch1 = "x86_64"
|
||||
ver1 = "v1"
|
||||
url1 = "http://localhost"
|
||||
md5hash1 = self.MD5HASH1
|
||||
hyper1 = "kvm"
|
||||
cmd1 = ' '.join((os1, arch1, ver1, url1, md5hash1, hyper1))
|
||||
|
||||
def test_agent_set(self):
|
||||
ver = 'v2'
|
||||
url = "http://openstack"
|
||||
md5hash = hashlib.md5().hexdigest()
|
||||
cmd_output = json.loads(self.openstack(
|
||||
'compute agent create -f json ' +
|
||||
cmd1
|
||||
))
|
||||
agent_id1 = str(cmd_output["agent_id"])
|
||||
self.addCleanup(self.openstack, 'compute agent delete ' + agent_id1)
|
||||
|
||||
self.openstack('compute agent set '
|
||||
+ self.ID
|
||||
+ ' --agent-version ' + ver
|
||||
+ ' --url ' + url
|
||||
+ ' --md5hash ' + md5hash)
|
||||
os2 = "os_2"
|
||||
arch2 = "x86"
|
||||
ver2 = "v2"
|
||||
url2 = "http://openstack"
|
||||
md5hash2 = self.MD5HASH2
|
||||
hyper2 = "xen"
|
||||
cmd2 = ' '.join((os2, arch2, ver2, url2, md5hash2, hyper2))
|
||||
|
||||
raw_output = self.openstack('compute agent list')
|
||||
self.assertIn(self.ID, raw_output)
|
||||
self.assertIn(ver, raw_output)
|
||||
self.assertIn(url, raw_output)
|
||||
self.assertIn(md5hash, raw_output)
|
||||
cmd_output = json.loads(self.openstack(
|
||||
'compute agent create -f json ' +
|
||||
cmd2
|
||||
))
|
||||
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"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user