Moved set of asserts from post_servers_1234_action methods.
Methods tests.v1_1.fakes.FakeHTTPClient.post_servers_1234_action and tests.fixture_data.servers.V1.post_servers_1234_action contain a set of same asserts. These asserts moved to method check_server_actions. This method is shared between post_servers_1234_action methods. Some almost equal asserts are grouped. Change-Id: I2643e77fe30400d462731bbc57351460fb28dc92
This commit is contained in:
parent
0a60aae852
commit
aeb8c0c5e9
novaclient/tests/unit
@ -14,6 +14,7 @@ from oslo.serialization import jsonutils
|
||||
|
||||
from novaclient.tests.unit import fakes
|
||||
from novaclient.tests.unit.fixture_data import base
|
||||
from novaclient.tests.unit.v2 import fakes as v2_fakes
|
||||
|
||||
|
||||
class Base(base.Fixture):
|
||||
@ -382,43 +383,24 @@ class V1(Base):
|
||||
context.status_code = 202
|
||||
assert len(body.keys()) == 1
|
||||
action = list(body)[0]
|
||||
if action == 'reboot':
|
||||
assert list(body[action]) == ['type']
|
||||
assert body[action]['type'] in ['HARD', 'SOFT']
|
||||
|
||||
if v2_fakes.FakeHTTPClient.check_server_actions(body):
|
||||
# NOTE(snikitin): No need to do any operations here. This 'pass'
|
||||
# is needed to avoid AssertionError in the last 'else' statement
|
||||
# if we found 'action' in method check_server_actions and
|
||||
# raise AssertionError if we didn't find 'action' at all.
|
||||
pass
|
||||
elif action == 'rebuild':
|
||||
body = body[action]
|
||||
adminPass = body.get('adminPass', 'randompassword')
|
||||
assert 'imageRef' in body
|
||||
_body = self.server_1234.copy()
|
||||
_body['adminPass'] = adminPass
|
||||
elif action == 'resize':
|
||||
keys = body[action].keys()
|
||||
assert 'flavorRef' in keys
|
||||
elif action == 'confirmResize':
|
||||
assert body[action] is None
|
||||
# This one method returns a different response code
|
||||
context.status_code = 204
|
||||
return None
|
||||
elif action == 'revertResize':
|
||||
assert body[action] is None
|
||||
elif action == 'migrate':
|
||||
assert body[action] is None
|
||||
elif action == 'os-stop':
|
||||
assert body[action] is None
|
||||
elif action == 'os-start':
|
||||
assert body[action] is None
|
||||
elif action == 'forceDelete':
|
||||
assert body[action] is None
|
||||
elif action == 'restore':
|
||||
assert body[action] is None
|
||||
elif action == 'pause':
|
||||
assert body[action] is None
|
||||
elif action == 'unpause':
|
||||
assert body[action] is None
|
||||
elif action == 'lock':
|
||||
assert body[action] is None
|
||||
elif action == 'unlock':
|
||||
assert body[action] is None
|
||||
elif action == 'rescue':
|
||||
if body[action]:
|
||||
keys = set(body[action].keys())
|
||||
@ -426,65 +408,15 @@ class V1(Base):
|
||||
else:
|
||||
assert body[action] is None
|
||||
_body = {'adminPass': 'RescuePassword'}
|
||||
elif action == 'unrescue':
|
||||
assert body[action] is None
|
||||
elif action == 'resume':
|
||||
assert body[action] is None
|
||||
elif action == 'suspend':
|
||||
assert body[action] is None
|
||||
elif action == 'lock':
|
||||
assert body[action] is None
|
||||
elif action == 'unlock':
|
||||
assert body[action] is None
|
||||
elif action == 'shelve':
|
||||
assert body[action] is None
|
||||
elif action == 'shelveOffload':
|
||||
assert body[action] is None
|
||||
elif action == 'unshelve':
|
||||
assert body[action] is None
|
||||
elif action == 'addFixedIp':
|
||||
assert list(body[action]) == ['networkId']
|
||||
elif action == 'removeFixedIp':
|
||||
assert list(body[action]) == ['address']
|
||||
elif action == 'addFloatingIp':
|
||||
assert (list(body[action]) == ['address'] or
|
||||
sorted(list(body[action])) == ['address',
|
||||
'fixed_address'])
|
||||
elif action == 'removeFloatingIp':
|
||||
assert list(body[action]) == ['address']
|
||||
elif action == 'createImage':
|
||||
assert set(body[action].keys()) == set(['name', 'metadata'])
|
||||
context.headers['location'] = "http://blah/images/456"
|
||||
elif action == 'changePassword':
|
||||
assert list(body[action]) == ['adminPass']
|
||||
elif action == 'os-getConsoleOutput':
|
||||
assert list(body[action]) == ['length']
|
||||
context.status_code = 202
|
||||
return {'output': 'foo'}
|
||||
elif action == 'os-getVNCConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-getSPICEConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-getRDPConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-getSerialConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-migrateLive':
|
||||
assert set(body[action].keys()) == set(['host',
|
||||
'block_migration',
|
||||
'disk_over_commit'])
|
||||
elif action == 'os-resetState':
|
||||
assert list(body[action]) == ['state']
|
||||
elif action == 'resetNetwork':
|
||||
assert body[action] is None
|
||||
elif action == 'addSecurityGroup':
|
||||
assert list(body[action]) == ['name']
|
||||
elif action == 'removeSecurityGroup':
|
||||
assert list(body[action]) == ['name']
|
||||
elif action == 'createBackup':
|
||||
assert set(body[action]) == set(['name',
|
||||
'backup_type',
|
||||
'rotation'])
|
||||
elif action == 'evacuate':
|
||||
keys = list(body[action])
|
||||
if 'adminPass' in keys:
|
||||
|
@ -542,48 +542,73 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
# Server actions
|
||||
#
|
||||
|
||||
none_actions = ['revertResize', 'migrate', 'os-stop', 'os-start',
|
||||
'forceDelete', 'restore', 'pause', 'unpause', 'unlock',
|
||||
'unrescue', 'resume', 'suspend', 'lock', 'shelve',
|
||||
'shelveOffload', 'unshelve', 'resetNetwork']
|
||||
type_actions = ['os-getVNCConsole', 'os-getSPICEConsole',
|
||||
'os-getRDPConsole']
|
||||
|
||||
@classmethod
|
||||
def check_server_actions(cls, body):
|
||||
action = list(body)[0]
|
||||
if action == 'reboot':
|
||||
assert list(body[action]) == ['type']
|
||||
assert body[action]['type'] in ['HARD', 'SOFT']
|
||||
elif action == 'resize':
|
||||
assert 'flavorRef' in body[action]
|
||||
elif action in cls.none_actions:
|
||||
assert body[action] is None
|
||||
elif action == 'addFixedIp':
|
||||
assert list(body[action]) == ['networkId']
|
||||
elif action in ['removeFixedIp', 'removeFloatingIp']:
|
||||
assert list(body[action]) == ['address']
|
||||
elif action == 'addFloatingIp':
|
||||
assert (list(body[action]) == ['address'] or
|
||||
sorted(list(body[action])) == ['address', 'fixed_address'])
|
||||
elif action == 'changePassword':
|
||||
assert list(body[action]) == ['adminPass']
|
||||
elif action in cls.type_actions:
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-migrateLive':
|
||||
assert set(body[action].keys()) == set(['host', 'block_migration',
|
||||
'disk_over_commit'])
|
||||
elif action == 'os-resetState':
|
||||
assert list(body[action]) == ['state']
|
||||
elif action == 'resetNetwork':
|
||||
assert body[action] is None
|
||||
elif action in ['addSecurityGroup', 'removeSecurityGroup']:
|
||||
assert list(body[action]) == ['name']
|
||||
elif action == 'createBackup':
|
||||
assert set(body[action]) == set(['name', 'backup_type',
|
||||
'rotation'])
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
def post_servers_1234_action(self, body, **kw):
|
||||
_headers = None
|
||||
_body = None
|
||||
resp = 202
|
||||
assert len(body.keys()) == 1
|
||||
action = list(body)[0]
|
||||
if action == 'reboot':
|
||||
assert list(body[action]) == ['type']
|
||||
assert body[action]['type'] in ['HARD', 'SOFT']
|
||||
|
||||
if self.check_server_actions(body):
|
||||
# NOTE(snikitin): No need to do any operations here. This 'pass'
|
||||
# is needed to avoid AssertionError in the last 'else' statement
|
||||
# if we found 'action' in method check_server_actions and
|
||||
# raise AssertionError if we didn't find 'action' at all.
|
||||
pass
|
||||
elif action == 'rebuild':
|
||||
body = body[action]
|
||||
adminPass = body.get('adminPass', 'randompassword')
|
||||
assert 'imageRef' in body
|
||||
_body = self.get_servers_1234()[2]
|
||||
_body['server']['adminPass'] = adminPass
|
||||
elif action == 'resize':
|
||||
keys = body[action].keys()
|
||||
assert 'flavorRef' in keys
|
||||
elif action == 'confirmResize':
|
||||
assert body[action] is None
|
||||
# This one method returns a different response code
|
||||
return (204, {}, None)
|
||||
elif action == 'revertResize':
|
||||
assert body[action] is None
|
||||
elif action == 'migrate':
|
||||
assert body[action] is None
|
||||
elif action == 'os-stop':
|
||||
assert body[action] is None
|
||||
elif action == 'os-start':
|
||||
assert body[action] is None
|
||||
elif action == 'forceDelete':
|
||||
assert body[action] is None
|
||||
elif action == 'restore':
|
||||
assert body[action] is None
|
||||
elif action == 'pause':
|
||||
assert body[action] is None
|
||||
elif action == 'unpause':
|
||||
assert body[action] is None
|
||||
elif action == 'lock':
|
||||
assert body[action] is None
|
||||
elif action == 'unlock':
|
||||
assert body[action] is None
|
||||
elif action == 'rescue':
|
||||
if body[action]:
|
||||
keys = set(body[action].keys())
|
||||
@ -591,62 +616,12 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
else:
|
||||
assert body[action] is None
|
||||
_body = {'adminPass': 'RescuePassword'}
|
||||
elif action == 'unrescue':
|
||||
assert body[action] is None
|
||||
elif action == 'resume':
|
||||
assert body[action] is None
|
||||
elif action == 'suspend':
|
||||
assert body[action] is None
|
||||
elif action == 'lock':
|
||||
assert body[action] is None
|
||||
elif action == 'unlock':
|
||||
assert body[action] is None
|
||||
elif action == 'shelve':
|
||||
assert body[action] is None
|
||||
elif action == 'shelveOffload':
|
||||
assert body[action] is None
|
||||
elif action == 'unshelve':
|
||||
assert body[action] is None
|
||||
elif action == 'addFixedIp':
|
||||
assert list(body[action]) == ['networkId']
|
||||
elif action == 'removeFixedIp':
|
||||
assert list(body[action]) == ['address']
|
||||
elif action == 'addFloatingIp':
|
||||
assert (list(body[action]) == ['address'] or
|
||||
sorted(list(body[action])) == ['address',
|
||||
'fixed_address'])
|
||||
elif action == 'removeFloatingIp':
|
||||
assert list(body[action]) == ['address']
|
||||
elif action == 'createImage':
|
||||
assert set(body[action].keys()) == set(['name', 'metadata'])
|
||||
_headers = dict(location="http://blah/images/456")
|
||||
elif action == 'changePassword':
|
||||
assert list(body[action]) == ['adminPass']
|
||||
elif action == 'os-getConsoleOutput':
|
||||
assert list(body[action]) == ['length']
|
||||
return (202, {}, {'output': 'foo'})
|
||||
elif action == 'os-getVNCConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-getSPICEConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-getRDPConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-migrateLive':
|
||||
assert set(body[action].keys()) == set(['host',
|
||||
'block_migration',
|
||||
'disk_over_commit'])
|
||||
elif action == 'os-resetState':
|
||||
assert list(body[action]) == ['state']
|
||||
elif action == 'resetNetwork':
|
||||
assert body[action] is None
|
||||
elif action == 'addSecurityGroup':
|
||||
assert list(body[action]) == ['name']
|
||||
elif action == 'removeSecurityGroup':
|
||||
assert list(body[action]) == ['name']
|
||||
elif action == 'createBackup':
|
||||
assert set(body[action]) == set(['name',
|
||||
'backup_type',
|
||||
'rotation'])
|
||||
elif action == 'evacuate':
|
||||
keys = list(body[action])
|
||||
if 'adminPass' in keys:
|
||||
|
Loading…
x
Reference in New Issue
Block a user