Add test case for requested host
Depends-On: https://review.opendev.org/#/c/711864/ Change-Id: I78f534c6464231059806c008de278f4a13e8fc31
This commit is contained in:
parent
a6a9b3919e
commit
a5ff9442ec
@ -28,6 +28,7 @@ from tempest import manager
|
||||
|
||||
from zun_tempest_plugin.tests.tempest.api.models import capsule_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import container_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import host_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import service_model
|
||||
from zun_tempest_plugin.tests.tempest import utils
|
||||
|
||||
@ -206,6 +207,11 @@ class ZunClient(rest_client.RestClient):
|
||||
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def hosts_uri(cls):
|
||||
url = "/hosts/"
|
||||
return url
|
||||
|
||||
def post_container(self, model, **kwargs):
|
||||
"""Makes POST /container request
|
||||
|
||||
@ -408,6 +414,11 @@ class ZunClient(rest_client.RestClient):
|
||||
def delete_network(self, network_id, params=None):
|
||||
return self.delete(self.network_uri(network_id, params=params))
|
||||
|
||||
def list_hosts(self, **kwargs):
|
||||
resp, body = self.get(self.hosts_uri(), **kwargs)
|
||||
return self.deserialize(resp, body,
|
||||
host_model.HostCollection)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def docker_client(docker_auth_url):
|
||||
|
30
zun_tempest_plugin/tests/tempest/api/models/host_model.py
Normal file
30
zun_tempest_plugin/tests/tempest/api/models/host_model.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from zun_tempest_plugin.tests.tempest.api.common import base_model
|
||||
|
||||
|
||||
class HostData(base_model.BaseModel):
|
||||
"""Data that encapsulates host attributes"""
|
||||
pass
|
||||
|
||||
|
||||
class HostEntity(base_model.EntityModel):
|
||||
"""Entity Model that represents a single instance of HostData"""
|
||||
ENTITY_NAME = 'host'
|
||||
MODEL_TYPE = HostData
|
||||
|
||||
|
||||
class HostCollection(base_model.CollectionModel):
|
||||
"""Collection Model that represents a list of HostData objects"""
|
||||
COLLECTION_NAME = 'hosts'
|
||||
MODEL_TYPE = HostData
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from io import BytesIO
|
||||
import random
|
||||
import tarfile
|
||||
import testtools
|
||||
import time
|
||||
@ -518,6 +519,20 @@ class TestContainer(base.BaseZunTest):
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertTrue(file_content in encodeutils.safe_decode(body))
|
||||
|
||||
@decorators.idempotent_id('0c8afb23-312d-4647-897d-b3c8591b26eb')
|
||||
@utils.requires_microversion('1.39')
|
||||
def test_run_container_with_requested_host(self):
|
||||
_, model = self.os_admin.container_client.list_hosts()
|
||||
hosts = model.hosts
|
||||
self.assertTrue(len(hosts) > 0)
|
||||
|
||||
# create a container with the requested host
|
||||
requested_host = random.choice(hosts).hostname
|
||||
_, model = self._run_container(
|
||||
container_client=self.os_admin.container_client,
|
||||
host=requested_host)
|
||||
self.assertEqual(requested_host, model.host)
|
||||
|
||||
@decorators.idempotent_id('c3f02fa0-fdfb-49fc-95e2-6e4dc982f9be')
|
||||
def test_commit_container(self):
|
||||
"""Test container snapshot
|
||||
@ -728,18 +743,20 @@ class TestContainer(base.BaseZunTest):
|
||||
return resp, model
|
||||
|
||||
def _run_container(self, gen_model=None, desired_state='Running',
|
||||
**kwargs):
|
||||
container_client=None, **kwargs):
|
||||
if gen_model is None:
|
||||
gen_model = datagen.container_data(**kwargs)
|
||||
resp, model = self.container_client.run_container(gen_model)
|
||||
if container_client is None:
|
||||
container_client = self.container_client
|
||||
resp, model = container_client.run_container(gen_model)
|
||||
self.containers.append(model.uuid)
|
||||
self.assertEqual(202, resp.status)
|
||||
# Wait for container to started
|
||||
self.container_client.ensure_container_in_desired_state(
|
||||
container_client.ensure_container_in_desired_state(
|
||||
model.uuid, desired_state)
|
||||
|
||||
# Assert the container is started
|
||||
resp, model = self.container_client.get_container(model.uuid)
|
||||
resp, model = container_client.get_container(model.uuid)
|
||||
self.assertEqual(desired_state, model.status)
|
||||
return resp, model
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user