Skip to content

Commit

Permalink
Functional tests for instance-count action on nova-compute charm. (#…
Browse files Browse the repository at this point in the history
…535)

Launchpad: #1911011
Gerrit review: https://review.opendev.org/c/openstack/charm-nova-compute/+/783371

* Functional tests for `instance-count` action on nova-compute charm.

Test for `remove_from_cloud_actions` waits at the end until
the nova-compute service is available again. However there's a few
seconds lag until that host shows up also in `hypervisor-list` which
can cause race conditions with other tests.
  • Loading branch information
mkalcok committed May 13, 2021
1 parent 3c0b47a commit 3aacd5c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion zaza/openstack/charm_tests/nova/tests.py
Expand Up @@ -143,7 +143,39 @@ def test_940_enable_disable_actions(self):
for service in self.nova_client.services.list(binary='nova-compute'):
self.assertEqual(service.status, 'enabled')

def test_950_remove_from_cloud_actions(self):
def test_950_instance_count_action(self):
"""Test that action 'instance-count' returns expected values."""
def check_instance_count(expect_count, unit_name):
"""Assert that unit with 'unit_name' has 'expect_count' of VMs.
:param expect_count: How many VMs are expected to be running
:param unit_name: Name of the target nova-compute unit
:return: None
:raises AssertionError: If result of the 'instance-count' action
does not match 'expect_count'.
"""
logging.debug('Running "instance-count" action on unit "{}".'
'Expecting result: {}'.format(unit_name,
expect_count))
result = zaza.model.run_action(unit_name, 'instance-count')
self.assertEqual(result.status, 'completed')
instances = result.data.get('results', {}).get('instance-count')
self.assertEqual(instances, str(expect_count))

nova_unit = zaza.model.get_units('nova-compute',
model_name=self.model_name)[0]

check_instance_count(0, nova_unit.entity_id)

self.RESOURCE_PREFIX = 'zaza-nova'
self.launch_guest(
'ubuntu', instance_key=glance_setup.LTS_IMAGE_NAME)

check_instance_count(1, nova_unit.entity_id)

self.resource_cleanup()

def test_960_remove_from_cloud_actions(self):
"""Test actions remove-from-cloud and register-to-cloud.
Note (martin-kalcok): This test requires that nova-compute unit is not
Expand Down

0 comments on commit 3aacd5c

Please sign in to comment.