Browse files

Merge "Extend test coverage for v1_1/shell.py"

  • Loading branch information...
2 parents 219f1df + 650f1c3 commit 9f4ef600e8543b276ecbd7925bddea43b0adc858 Jenkins committed with openstack-gerrit Mar 11, 2013
Showing with 218 additions and 7 deletions.
  1. +63 −0 tests/v1_1/fakes.py
  2. +155 −7 tests/v1_1/test_shell.py
View
63 tests/v1_1/fakes.py
@@ -474,10 +474,27 @@ def post_servers_1234_action(self, body, **kw):
assert body[action] is None
elif action == 'os-start':
assert body[action] is None
+ elif action == 'start':
+ assert body[action] is None
+ elif action == 'stop':
+ 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':
assert body[action] is None
+ _body = {'Password': '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':
@@ -1630,3 +1647,49 @@ def post_servers_1234_os_interface(self, **kw):
def delete_servers_1234_os_interface_port_id(self, **kw):
return (200, {}, None)
+
+ # NOTE (vkhomenko):
+ # Volume responses was taken from:
+ # https://wiki.openstack.org/wiki/CreateVolumeFromImage
+ # http://jorgew.github.com/block-storage-api/content/
+ # GET_listDetailVolumes_v1__tenantId__volumes_detail_.html
+ # I suppose they are outdated and should be updated after Cinder released
+
+ def get_volumes_detail(self, **kw):
+ return (200, {}, {"volumes": [
+ {"display_name": "Work",
+ "display_description": "volume for work",
+ "status": "ATTACHED",
+ "id": "15e59938-07d5-11e1-90e3-e3dffe0c5983",
+ "created_at": "2011-09-09T00:00:00Z",
+ "attached": "2011-11-11T00:00:00Z",
+ "size": 1024,
+ "attachments": [
+ {"id": "3333",
+ "links": ''}],
+ "metadata": {}}]})
+
+ def post_volumes(self, **kw):
+ return (200, {}, {"volume":
+ {"status": "creating",
+ "display_name": "vol-007",
+ "attachments": [(0)],
+ "availability_zone": "cinder",
+ "created_at": "2012-08-13T10:57:17.000000",
+ "display_description": "create volume from image",
+ "image_id": "f4cf905f-7c58-4d7b-8314-8dd8a2d1d483",
+ "volume_type": "None",
+ "metadata": {},
+ "id": "5cb239f6-1baf-4fe1-bd78-c852cf00fa39",
+ "size": 1}})
+
+ def delete_volumes_15e59938_07d5_11e1_90e3_e3dffe0c5983(self, **kw):
+ return (200, {}, {})
+
+ def post_servers_1234_os_volume_attachments(self, **kw):
+ return (200, {}, {"volumeAttachment":
+ {"device": "/dev/vdb",
+ "volumeId": 2}})
+
+ def delete_servers_1234_os_volume_attachments_Work(self, **kw):
+ return (200, {}, {})
View
162 tests/v1_1/test_shell.py
@@ -125,6 +125,20 @@ def test_boot(self):
}},
)
+ def test_boot_multiple(self):
+ self.run_command('boot --flavor 1 --image 1'
+ ' --num-instances 3 some-server')
+ self.assert_called_anytime(
+ 'POST', '/servers',
+ {'server': {
+ 'flavorRef': '1',
+ 'name': 'some-server',
+ 'imageRef': '1',
+ 'min_count': 1,
+ 'max_count': 3,
+ }},
+ )
+
def test_boot_image_with(self):
self.run_command("boot --flavor 1"
" --image-with test_key=test_value some-server")
@@ -466,6 +480,14 @@ def test_list(self):
self.run_command('list')
self.assert_called('GET', '/servers/detail')
+ def test_list_with_images(self):
+ self.run_command('list --image 1')
+ self.assert_called('GET', '/servers/detail?image=1')
+
+ def test_list_with_flavors(self):
+ self.run_command('list --flavor 1')
+ self.assert_called('GET', '/servers/detail?flavor=1')
+
@mock.patch('sys.stdout', StringIO.StringIO())
def test_list_fields(self):
self.run_command('list --fields '
@@ -486,17 +508,63 @@ def test_reboot(self):
def test_rebuild(self):
self.run_command('rebuild sample-server 1')
- # XXX need a way to test multiple calls
- # self.assert_called('POST', '/servers/1234/action',
- # {'rebuild': {'imageRef': 1}})
+ self.assert_called('POST', '/servers/1234/action',
+ {'rebuild': {'imageRef': 1}}, pos=-4)
+ self.assert_called('GET', '/servers/detail', pos=-3)
+ self.assert_called('GET', '/flavors/1', pos=-2)
self.assert_called('GET', '/images/2')
self.run_command('rebuild sample-server 1 --rebuild-password asdf')
- # XXX need a way to test multiple calls
- # self.assert_called('POST', '/servers/1234/action',
- # {'rebuild': {'imageRef': 1, 'adminPass': 'asdf'}})
+ self.assert_called('POST', '/servers/1234/action',
+ {'rebuild': {'imageRef': 1, 'adminPass': 'asdf'}},
+ pos=-4)
+ self.assert_called('GET', '/flavors/1', pos=-2)
self.assert_called('GET', '/images/2')
+ def test_start(self):
+ self.run_command('start sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'os-start': None})
+
+ def test_stop(self):
+ self.run_command('stop sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'os-stop': None})
+
+ def test_pause(self):
+ self.run_command('pause sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'pause': None})
+
+ def test_unpause(self):
+ self.run_command('unpause sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'unpause': None})
+
+ def test_lock(self):
+ self.run_command('lock sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'lock': None})
+
+ def test_unlock(self):
+ self.run_command('unlock sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'unlock': None})
+
+ def test_suspend(self):
+ self.run_command('suspend sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'suspend': None})
+
+ def test_resume(self):
+ self.run_command('resume sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'resume': None})
+
+ def test_rescue(self):
+ self.run_command('rescue sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'rescue': None})
+
+ def test_unrescue(self):
+ self.run_command('unrescue sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'unrescue': None})
+
+ def test_migrate(self):
+ self.run_command('migrate sample-server')
+ self.assert_called('POST', '/servers/1234/action', {'migrate': None})
+
def test_rename(self):
self.run_command('rename sample-server newname')
self.assert_called('PUT', '/servers/1234',
@@ -622,6 +690,18 @@ def test_dns_domains(self):
self.run_command('dns-domains')
self.assert_called('GET', '/os-floating-ip-dns')
+ def test_floating_ip_list(self):
+ self.run_command('floating-ip-list')
+ self.assert_called('GET', '/os-floating-ips')
+
+ def test_floating_ip_create(self):
+ self.run_command('floating-ip-create')
+ self.assert_called('GET', '/os-floating-ips/1')
+
+ def test_floating_ip_delete(self):
+ self.run_command('floating-ip-delete 11.0.0.1')
+ self.assert_called('DELETE', '/os-floating-ips/1')
+
def test_floating_ip_bulk_list(self):
self.run_command('floating-ip-bulk-list')
self.assert_called('GET', '/os-floating-ips-bulk')
@@ -646,6 +726,16 @@ def test_floating_ip_bulk_delete(self):
self.assert_called('PUT', '/os-floating-ips-bulk/delete',
{'ip_range': '10.0.0.1/24'})
+ def test_server_floating_ip_add(self):
+ self.run_command('add-floating-ip sample-server 11.0.0.1')
+ self.assert_called('POST', '/servers/1234/action',
+ {'addFloatingIp': {'address': '11.0.0.1'}})
+
+ def test_server_floating_ip_remove(self):
+ self.run_command('remove-floating-ip sample-server 11.0.0.1')
+ self.assert_called('POST', '/servers/1234/action',
+ {'removeFloatingIp': {'address': '11.0.0.1'}})
+
def test_usage_list(self):
self.run_command('usage-list --start 2000-01-20 --end 2005-02-01')
self.assert_called('GET',
@@ -996,6 +1086,16 @@ def test_network_create_invalid(self):
cmd = 'network-create 10.0.1.0'
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
+ def test_add_fixed_ip(self):
+ self.run_command('add-fixed-ip sample-server 1')
+ self.assert_called('POST', '/servers/1234/action',
+ {'addFixedIp': {'networkId': '1'}})
+
+ def test_remove_fixed_ip(self):
+ self.run_command('remove-fixed-ip sample-server 10.0.0.10')
+ self.assert_called('POST', '/servers/1234/action',
+ {'removeFixedIp': {'address': '10.0.0.10'}})
+
def test_backup(self):
self.run_command('backup sample-server back1 daily 1')
self.assert_called('POST', '/servers/1234/action',
@@ -1109,14 +1209,62 @@ def test_security_group_delete(self):
self.run_command('secgroup-delete test')
self.assert_called('DELETE', '/os-security-groups/1')
+ def test_server_security_group_add(self):
+ self.run_command('add-secgroup sample-server testgroup')
+ self.assert_called('POST', '/servers/1234/action',
+ {'addSecurityGroup': {'name': 'testgroup'}})
+
+ def test_server_security_group_remove(self):
+ self.run_command('remove-secgroup sample-server testgroup')
+ self.assert_called('POST', '/servers/1234/action',
+ {'removeSecurityGroup': {'name': 'testgroup'}})
+
def test_interface_list(self):
self.run_command('interface-list 1234')
self.assert_called('GET', '/servers/1234/os-interface')
def test_interface_attach(self):
self.run_command('interface-attach --port-id port_id 1234')
- self.assert_called('POST', '/servers/1234/os-interface')
+ self.assert_called('POST', '/servers/1234/os-interface',
+ {'interfaceAttachment': {'port_id': 'port_id'}})
def test_interface_detach(self):
self.run_command('interface-detach 1234 port_id')
self.assert_called('DELETE', '/servers/1234/os-interface/port_id')
+
+ def test_volume_list(self):
+ self.run_command('volume-list')
+ self.assert_called('GET', '/volumes/detail')
+
+ def test_volume_show(self):
+ self.run_command('volume-show Work')
+ self.assert_called('GET', '/volumes/detail')
+
+ def test_volume_create(self):
+ self.run_command('volume-create 2 --display-name Work')
+ self.assert_called('POST', '/volumes',
+ {'volume':
+ {'display_name': 'Work',
+ 'imageRef': None,
+ 'availability_zone': None,
+ 'volume_type': None,
+ 'display_description': None,
+ 'snapshot_id': None,
+ 'size': 2}})
+
+ def test_volume_delete(self):
+ self.run_command('volume-delete Work')
+ self.assert_called('DELETE',
+ '/volumes/15e59938-07d5-11e1-90e3-e3dffe0c5983')
+
+ def test_volume_attach(self):
+ self.run_command('volume-attach sample-server Work /dev/vdb')
+ self.assert_called('POST', '/servers/1234/os-volume_attachments',
+ {'volumeAttachment':
+ {'device': '/dev/vdb',
+ 'volumeId': 'Work'}})
+
+ def test_volume_detach(self):
+ self.run_command('volume-detach sample-server Work')
+ self.assert_called('DELETE',
+ '/servers/1234/os-volume_attachments/Work')

0 comments on commit 9f4ef60

Please sign in to comment.