Fixed an issue that container's host is None

In before, if cpu and memory is not specified, the container's host
is not populated even if the claim succeeded. This commit fixed it.
In addition, add tempest test to verify it.

Change-Id: I2766e9539ecd1abf46f88f190600907fe6ff1021
Closes-Bug: #1701853
This commit is contained in:
Hongbin Lu 2017-07-01 21:46:01 +00:00
parent 5464b393fe
commit 58009529c9
3 changed files with 28 additions and 19 deletions

View File

@ -81,6 +81,7 @@ class ComputeNodeTracker(object):
"""
# No memory and cpu specified, no need to claim resource now.
if not (container.memory or container.cpu):
self._set_container_host(container)
return claims.NopClaim()
# We should have the compute node created here, just get it.

View File

@ -47,24 +47,25 @@ def gen_url(scheme="http", domain="example.com", port=80):
return "%s://%s:%s" % (scheme, domain, port)
def container_data(**kwargs):
data = {
'name': data_utils.rand_name('container'),
'image': 'cirros:latest',
'command': 'sleep 10000',
'cpu': 0.1,
'memory': '100',
'environment': {},
'labels': {},
'image_driver': 'docker',
'image_pull_policy': 'always',
'restart_policy': {'Name': 'no'},
'workdir': '/',
'interactive': False
}
def container_data(default_data=None, **kwargs):
if default_data is None:
default_data = {
'name': data_utils.rand_name('container'),
'image': 'cirros:latest',
'command': 'sleep 10000',
'cpu': 0.1,
'memory': '100',
'environment': {},
'labels': {},
'image_driver': 'docker',
'image_pull_policy': 'always',
'restart_policy': {'Name': 'no'},
'workdir': '/',
'interactive': False
}
data.update(kwargs)
model = container_model.ContainerEntity.from_dict(data)
default_data.update(kwargs)
model = container_model.ContainerEntity.from_dict(default_data)
return model

View File

@ -79,6 +79,11 @@ class TestContainer(base.BaseZunTest):
def test_run_container(self):
self._run_container()
@decorators.idempotent_id('a2152d78-b6a6-4f47-8767-d83d29c6fb19')
def test_run_container_with_minimal_params(self):
gen_model = datagen.container_data({'image': 'nginx'})
self._run_container(gen_model=gen_model)
@decorators.idempotent_id('c32f93e3-da88-4c13-be38-25d2e662a28e')
def test_run_container_with_image_driver_glance(self):
image = None
@ -336,8 +341,9 @@ class TestContainer(base.BaseZunTest):
self.assertEqual('Created', self._get_container_state(model.uuid))
return resp, model
def _run_container(self, **kwargs):
gen_model = datagen.container_data(**kwargs)
def _run_container(self, gen_model=None, **kwargs):
if gen_model is None:
gen_model = datagen.container_data(**kwargs)
resp, model = self.container_client.run_container(gen_model)
self.assertEqual(202, resp.status)
# Wait for container to started
@ -348,6 +354,7 @@ class TestContainer(base.BaseZunTest):
resp, model = self.container_client.get_container(model.uuid)
self.assertEqual('Running', model.status)
self.assertEqual('Running', self._get_container_state(model.uuid))
self.assertIsNotNone(model.host)
return resp, model
def _delete_container(self, container_id):