Add unit test for different HM type

This patch adds a test case to cover the case when hm_type is specified
but it has other values like 'TCP' (in fact, 'PING' and other
possibilities exist).

Change-Id: If7990725966029066fa0643dd7b205a1e37785f1
This commit is contained in:
tengqm 2015-08-06 10:15:08 -04:00
parent 1ee0da3959
commit 50932bdd94
2 changed files with 19 additions and 8 deletions

View File

@ -316,6 +316,7 @@ class NeutronClient(base.DriverBase):
'admin_state_up': admin_state_up,
}
# TODO(anyone): verify if this is correct
if hm_type == 'HTTP':
if http_method is not None:
kwargs['http_method'] = http_method

View File

@ -484,21 +484,31 @@ class TestNeutronV2Driver(base.SenlinTestCase):
}
self.conn.network.create_health_monitor.return_value = hm_obj
self.assertEqual(hm_obj, self.nc.healthmonitor_create(
hm_type, delay, timeout, max_retries, pool_id, **kwargs))
res = self.nc.healthmonitor_create(hm_type, delay, timeout,
max_retries, pool_id, **kwargs)
self.assertEqual(hm_obj, res)
self.conn.network.create_health_monitor.assert_called_once_with(
type=hm_type, delay=delay, timeout=timeout,
max_retries=max_retries, pool_id=pool_id, **kwargs)
# Use default input parameters
kwargs = {
'admin_state_up': True
}
self.assertEqual(hm_obj, self.nc.healthmonitor_create(
hm_type, delay, timeout, max_retries, pool_id))
res = self.nc.healthmonitor_create(hm_type, delay, timeout,
max_retries, pool_id,
admin_state_up=True)
self.assertEqual(hm_obj, res)
self.conn.network.create_health_monitor.assert_called_with(
type=hm_type, delay=delay, timeout=timeout,
max_retries=max_retries, pool_id=pool_id, **kwargs)
max_retries=max_retries, pool_id=pool_id,
admin_state_up=True)
# hm_type other than HTTP, then other params ignored
res = self.nc.healthmonitor_create('TCP', delay, timeout,
max_retries, pool_id, **kwargs)
self.assertEqual(hm_obj, res)
self.conn.network.create_health_monitor.assert_called_with(
type='TCP', delay=delay, timeout=timeout,
max_retries=max_retries, pool_id=pool_id,
admin_state_up=True)
# Exception happened during creating progress
exception_info = 'Exception happened when creating healthmonitor.'