Merge "Convert admin.instances tests into mock"
This commit is contained in:
commit
892607890a
@ -15,10 +15,9 @@
|
||||
from collections import OrderedDict
|
||||
import uuid
|
||||
|
||||
from django import http
|
||||
from django.urls import reverse
|
||||
import mock
|
||||
|
||||
from mox3.mox import IsA
|
||||
from django.urls import reverse
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.test import helpers as test
|
||||
@ -29,106 +28,102 @@ INDEX_TEMPLATE = 'horizon/common/_data_table_view.html'
|
||||
|
||||
|
||||
class InstanceViewTest(test.BaseAdminViewTests):
|
||||
@test.create_stubs({
|
||||
api.nova: ('flavor_list', 'server_list', 'extension_supported',),
|
||||
api.keystone: ('tenant_list',),
|
||||
api.glance: ('image_list_detailed',),
|
||||
@test.create_mocks({
|
||||
api.nova: ['flavor_list', 'server_list', 'extension_supported'],
|
||||
api.keystone: ['tenant_list'],
|
||||
api.glance: ['image_list_detailed'],
|
||||
})
|
||||
def test_index(self):
|
||||
servers = self.servers.list()
|
||||
flavors = self.flavors.list()
|
||||
tenants = self.tenants.list()
|
||||
images = self.images.list()
|
||||
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.extension_supported('Shelve', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest)).\
|
||||
AndReturn([tenants, False])
|
||||
api.glance.image_list_detailed(IsA(http.HttpRequest))\
|
||||
.AndReturn((images, False, False))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors)
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
search_opts=search_opts) \
|
||||
.AndReturn([servers, False])
|
||||
self.mox.ReplayAll()
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_tenant_list.return_value = [self.tenants.list(), False]
|
||||
self.mock_image_list_detailed.return_value = (self.images.list(),
|
||||
False, False)
|
||||
self.mock_flavor_list.return_value = self.flavors.list()
|
||||
self.mock_server_list.return_value = [servers, False]
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertTemplateUsed(res, INDEX_TEMPLATE)
|
||||
instances = res.context['table'].data
|
||||
self.assertItemsEqual(instances, servers)
|
||||
|
||||
@test.create_stubs({
|
||||
api.nova: ('flavor_list', 'flavor_get', 'server_list',
|
||||
'extension_supported',),
|
||||
api.keystone: ('tenant_list',),
|
||||
api.glance: ('image_list_detailed',),
|
||||
self.mock_extension_supported.assert_has_calls([
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('Shelve', test.IsHttpRequest())]*4)
|
||||
self.assertEqual(12, self.mock_extension_supported.call_count)
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest())
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
self.mock_server_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), search_opts=search_opts)
|
||||
|
||||
@test.create_mocks({
|
||||
api.nova: ['flavor_list', 'flavor_get', 'server_list',
|
||||
'extension_supported'],
|
||||
api.keystone: ['tenant_list'],
|
||||
api.glance: ['image_list_detailed'],
|
||||
})
|
||||
def test_index_flavor_list_exception(self):
|
||||
servers = self.servers.list()
|
||||
tenants = self.tenants.list()
|
||||
flavors = self.flavors.list()
|
||||
images = self.images.list()
|
||||
full_flavors = OrderedDict([(f.id, f) for f in flavors])
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
search_opts=search_opts) \
|
||||
.AndReturn([servers, False])
|
||||
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.extension_supported('Shelve', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.glance.image_list_detailed(IsA(http.HttpRequest))\
|
||||
.AndReturn((images, False, False))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)). \
|
||||
AndRaise(self.exceptions.nova)
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest)).\
|
||||
AndReturn([tenants, False])
|
||||
for server in servers:
|
||||
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \
|
||||
AndReturn(full_flavors[server.flavor["id"]])
|
||||
self.mock_server_list.return_value = [servers, False]
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_flavor_list.side_effect = self.exceptions.nova
|
||||
self.mock_tenant_list.return_value = [self.tenants.list(), False]
|
||||
|
||||
self.mox.ReplayAll()
|
||||
def _get_full_flavor(request, id):
|
||||
return full_flavors[id]
|
||||
self.mock_flavor_get.side_effect = _get_full_flavor
|
||||
|
||||
self.mock_image_list_detailed.return_value = (self.images.list(),
|
||||
False, False)
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
|
||||
self.assertTemplateUsed(res, INDEX_TEMPLATE)
|
||||
instances = res.context['table'].data
|
||||
self.assertItemsEqual(instances, servers)
|
||||
|
||||
@test.create_stubs({
|
||||
api.nova: ('flavor_list', 'flavor_get', 'server_list',
|
||||
'extension_supported',),
|
||||
api.keystone: ('tenant_list',),
|
||||
api.glance: ('image_list_detailed',),
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
self.mock_server_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), search_opts=search_opts)
|
||||
self.mock_extension_supported.assert_has_calls([
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('Shelve', test.IsHttpRequest())]*4)
|
||||
self.assertEqual(12, self.mock_extension_supported.call_count)
|
||||
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_flavor_get.assert_has_calls(
|
||||
[mock.call(test.IsHttpRequest(), s.flavor['id']) for s in servers])
|
||||
self.assertEqual(len(servers), self.mock_flavor_get.call_count)
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
|
||||
@test.create_mocks({
|
||||
api.nova: ['flavor_list', 'flavor_get', 'server_list',
|
||||
'extension_supported'],
|
||||
api.keystone: ['tenant_list'],
|
||||
api.glance: ['image_list_detailed'],
|
||||
})
|
||||
def test_index_flavor_get_exception(self):
|
||||
servers = self.servers.list()
|
||||
flavors = self.flavors.list()
|
||||
images = self.images.list()
|
||||
tenants = self.tenants.list()
|
||||
# UUIDs generated using indexes are unlikely to match
|
||||
# any of existing flavor ids and are guaranteed to be deterministic.
|
||||
for i, server in enumerate(servers):
|
||||
server.flavor['id'] = str(uuid.UUID(int=i))
|
||||
|
||||
api.glance.image_list_detailed(IsA(http.HttpRequest))\
|
||||
.AndReturn((images, False, False))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors)
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
search_opts=search_opts) \
|
||||
.AndReturn([servers, False])
|
||||
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.extension_supported('Shelve', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest)).\
|
||||
AndReturn([tenants, False])
|
||||
for server in servers:
|
||||
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \
|
||||
AndRaise(self.exceptions.nova)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_image_list_detailed.return_value = \
|
||||
(self.images.list(), False, False)
|
||||
self.mock_flavor_list.return_value = self.flavors.list()
|
||||
self.mock_server_list.return_value = [servers, False]
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_tenant_list.return_value = [self.tenants.list(), False]
|
||||
self.mock_flavor_get.side_effect = self.exceptions.nova
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
instances = res.context['table'].data
|
||||
@ -139,51 +134,58 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
self.assertMessageCount(res, error=1)
|
||||
self.assertItemsEqual(instances, servers)
|
||||
|
||||
@test.create_stubs({
|
||||
api.nova: ('server_list', 'flavor_list',),
|
||||
api.keystone: ('tenant_list',),
|
||||
api.glance: ('image_list_detailed',),
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest())
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
self.mock_server_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), search_opts=search_opts)
|
||||
self.mock_extension_supported.assert_has_calls([
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('Shelve', test.IsHttpRequest())]*4)
|
||||
self.assertEqual(12, self.mock_extension_supported.call_count)
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_flavor_get.assert_has_calls(
|
||||
[mock.call(test.IsHttpRequest(), s.flavor['id']) for s in servers])
|
||||
self.assertEqual(len(servers), self.mock_flavor_get.call_count)
|
||||
|
||||
@test.create_mocks({
|
||||
api.nova: ['server_list', 'flavor_list'],
|
||||
api.keystone: ['tenant_list'],
|
||||
api.glance: ['image_list_detailed'],
|
||||
})
|
||||
def test_index_server_list_exception(self):
|
||||
tenants = self.tenants.list()
|
||||
images = self.images.list()
|
||||
flavors = self.flavors.list()
|
||||
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest)).\
|
||||
AndReturn([tenants, False])
|
||||
api.glance.image_list_detailed(IsA(http.HttpRequest))\
|
||||
.AndReturn((images, False, False))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors)
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
search_opts=search_opts) \
|
||||
.AndRaise(self.exceptions.nova)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_list.side_effect = self.exceptions.nova
|
||||
self.mock_flavor_list.return_value = self.flavors.list()
|
||||
self.mock_tenant_list.return_value = [self.tenants.list(), False]
|
||||
self.mock_image_list_detailed.return_value = (self.images.list(),
|
||||
False, False)
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertTemplateUsed(res, INDEX_TEMPLATE)
|
||||
self.assertEqual(len(res.context['instances_table'].data), 0)
|
||||
|
||||
@test.create_stubs({api.nova: ('server_get', 'flavor_get',
|
||||
'extension_supported', ),
|
||||
api.network: ('servers_update_addresses',),
|
||||
api.keystone: ('tenant_get',)})
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
self.mock_server_list.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
search_opts=search_opts)
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest())
|
||||
|
||||
@test.create_mocks({api.nova: ['server_get', 'flavor_get',
|
||||
'extension_supported'],
|
||||
api.network: ['servers_update_addresses'],
|
||||
api.keystone: ['tenant_get']})
|
||||
def test_ajax_loading_instances(self):
|
||||
server = self.servers.first()
|
||||
flavor = self.flavors.list()[0]
|
||||
tenant = self.tenants.list()[0]
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
|
||||
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.extension_supported('Shelve', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.flavor_get(IsA(http.HttpRequest),
|
||||
server.flavor['id']).AndReturn(flavor)
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest),
|
||||
server.tenant_id,
|
||||
admin=True).AndReturn(tenant)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_flavor_get.return_value = self.flavors.first()
|
||||
self.mock_tenant_get.return_value = self.tenants.first()
|
||||
self.mock_servers_update_addresses.return_value = None
|
||||
|
||||
url = (INDEX_URL +
|
||||
"?action=row_update&table=instances&obj_id=" + server.id)
|
||||
@ -203,39 +205,55 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
self.assertContains(res, "Active", 1, 200)
|
||||
self.assertContains(res, "Running", 1, 200)
|
||||
|
||||
@test.create_stubs({
|
||||
api.nova: ('flavor_list', 'server_list', 'extension_supported', ),
|
||||
api.keystone: ('tenant_list',),
|
||||
api.glance: ('image_list_detailed',),
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_extension_supported.assert_has_calls([
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('Shelve', test.IsHttpRequest())])
|
||||
self.assertEqual(3, self.mock_extension_supported.call_count)
|
||||
self.mock_flavor_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.flavor['id'])
|
||||
self.mock_tenant_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.tenant_id, admin=True)
|
||||
self.mock_servers_update_addresses.assert_called_once_with(
|
||||
test.IsHttpRequest(), [server])
|
||||
|
||||
@test.create_mocks({
|
||||
api.nova: ['flavor_list', 'server_list', 'extension_supported'],
|
||||
api.keystone: ['tenant_list'],
|
||||
api.glance: ['image_list_detailed'],
|
||||
})
|
||||
def test_index_options_before_migrate(self):
|
||||
servers = self.servers.list()
|
||||
images = self.images.list()
|
||||
flavors = self.flavors.list()
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest)).\
|
||||
AndReturn([self.tenants.list(), False])
|
||||
api.glance.image_list_detailed(IsA(http.HttpRequest)) \
|
||||
.AndReturn((images, False, False))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors)
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
search_opts=search_opts) \
|
||||
.AndReturn([servers, False])
|
||||
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.extension_supported('Shelve', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_tenant_list.return_value = [self.tenants.list(), False]
|
||||
self.mock_image_list_detailed.return_value = (self.images.list(),
|
||||
False, False)
|
||||
self.mock_flavor_list.return_value = self.flavors.list()
|
||||
self.mock_server_list.return_value = [self.servers.list(), False]
|
||||
self.mock_extension_supported.return_value = True
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertContains(res, "instances__migrate")
|
||||
self.assertNotContains(res, "instances__confirm")
|
||||
self.assertNotContains(res, "instances__revert")
|
||||
|
||||
@test.create_stubs({
|
||||
api.nova: ('flavor_list', 'server_list', 'extension_supported',),
|
||||
api.keystone: ('tenant_list',),
|
||||
api.glance: ('image_list_detailed',),
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest())
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
self.mock_server_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), search_opts=search_opts)
|
||||
self.mock_extension_supported.assert_has_calls([
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('Shelve', test.IsHttpRequest())]*4)
|
||||
self.assertEqual(12, self.mock_extension_supported.call_count)
|
||||
|
||||
@test.create_mocks({
|
||||
api.nova: ['flavor_list', 'server_list', 'extension_supported'],
|
||||
api.keystone: ['tenant_list'],
|
||||
api.glance: ['image_list_detailed'],
|
||||
})
|
||||
def test_index_options_after_migrate(self):
|
||||
servers = self.servers.list()
|
||||
@ -243,40 +261,39 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
server1.status = "VERIFY_RESIZE"
|
||||
server2 = servers[2]
|
||||
server2.status = "VERIFY_RESIZE"
|
||||
images = self.images.list()
|
||||
flavors = self.flavors.list()
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn([self.tenants.list(), False])
|
||||
api.glance.image_list_detailed(IsA(http.HttpRequest)) \
|
||||
.AndReturn((images, False, False))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors)
|
||||
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.nova.extension_supported('Shelve', IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
search_opts=search_opts) \
|
||||
.AndReturn([servers, False])
|
||||
self.mox.ReplayAll()
|
||||
self.mock_tenant_list.return_value = [self.tenants.list(), False]
|
||||
self.mock_image_list_detailed.return_value = (self.images.list(),
|
||||
False, False)
|
||||
self.mock_flavor_list.return_value = self.flavors.list()
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_server_list.return_value = [servers, False]
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertContains(res, "instances__confirm")
|
||||
self.assertContains(res, "instances__revert")
|
||||
self.assertNotContains(res, "instances__migrate")
|
||||
|
||||
@test.create_stubs({api.nova: ('service_list',
|
||||
'server_get',)})
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_extension_supported.assert_has_calls([
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('AdminActions', test.IsHttpRequest()),
|
||||
mock.call('Shelve', test.IsHttpRequest())]*4)
|
||||
self.assertEqual(12, self.mock_extension_supported.call_count)
|
||||
search_opts = {'marker': None, 'paginate': True, 'all_tenants': True}
|
||||
self.mock_server_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), search_opts=search_opts)
|
||||
|
||||
@test.create_mocks({api.nova: ['service_list',
|
||||
'server_get']})
|
||||
def test_instance_live_migrate_get(self):
|
||||
server = self.servers.first()
|
||||
compute_services = [s for s in self.services.list()
|
||||
if s.binary == 'nova-compute']
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndReturn(server)
|
||||
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
|
||||
.AndReturn(compute_services)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_service_list.return_value = compute_services
|
||||
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
@ -284,13 +301,15 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
|
||||
self.assertTemplateUsed(res, 'admin/instances/live_migrate.html')
|
||||
|
||||
@test.create_stubs({api.nova: ('server_get',)})
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_service_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), binary='nova-compute')
|
||||
|
||||
@test.create_mocks({api.nova: ['server_get']})
|
||||
def test_instance_live_migrate_get_server_get_exception(self):
|
||||
server = self.servers.first()
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndRaise(self.exceptions.nova)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.side_effect = self.exceptions.nova
|
||||
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
@ -298,38 +317,40 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.nova: ('service_list',
|
||||
'server_get',)})
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
|
||||
@test.create_mocks({api.nova: ['service_list',
|
||||
'server_get']})
|
||||
def test_instance_live_migrate_list_host_get_exception(self):
|
||||
server = self.servers.first()
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndReturn(server)
|
||||
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
|
||||
.AndRaise(self.exceptions.nova)
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_service_list.side_effect = self.exceptions.nova
|
||||
|
||||
self.mox.ReplayAll()
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.nova: ('service_list',
|
||||
'server_get',)})
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_service_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), binary='nova-compute')
|
||||
|
||||
@test.create_mocks({api.nova: ['service_list',
|
||||
'server_get']})
|
||||
def test_instance_live_migrate_list_host_without_current(self):
|
||||
server = self.servers.first()
|
||||
compute_services = [s for s in self.services.list()
|
||||
if s.binary == 'nova-compute']
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndReturn(server)
|
||||
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
|
||||
.AndReturn(compute_services)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_service_list.return_value = compute_services
|
||||
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertContains(
|
||||
res, "<option value=\"devstack001\">devstack001</option>")
|
||||
self.assertContains(
|
||||
@ -337,90 +358,100 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
self.assertNotContains(
|
||||
res, "<option value=\"instance-host\">instance-host</option>")
|
||||
|
||||
@test.create_stubs({api.nova: ('service_list',
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_service_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), binary='nova-compute')
|
||||
|
||||
@test.create_mocks({api.nova: ['service_list',
|
||||
'server_get',
|
||||
'server_live_migrate',)})
|
||||
'server_live_migrate']})
|
||||
def test_instance_live_migrate_post(self):
|
||||
server = self.servers.first()
|
||||
compute_services = [s for s in self.services.list()
|
||||
if s.binary == 'nova-compute']
|
||||
host = compute_services[0].host
|
||||
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndReturn(server)
|
||||
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
|
||||
.AndReturn(compute_services)
|
||||
api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, host,
|
||||
block_migration=False,
|
||||
disk_over_commit=False) \
|
||||
.AndReturn([])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_service_list.return_value = compute_services
|
||||
self.mock_server_live_migrate.return_value = []
|
||||
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
res = self.client.post(url, {'host': host, 'instance_id': server.id})
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.nova: ('service_list',
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_service_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), binary='nova-compute')
|
||||
self.mock_server_live_migrate.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id, host,
|
||||
block_migration=False,
|
||||
disk_over_commit=False)
|
||||
|
||||
@test.create_mocks({api.nova: ['service_list',
|
||||
'server_get',
|
||||
'server_live_migrate',)})
|
||||
'server_live_migrate']})
|
||||
def test_instance_live_migrate_auto_sched(self):
|
||||
server = self.servers.first()
|
||||
host = "AUTO_SCHEDULE"
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndReturn(server)
|
||||
self.mock_server_get.return_value = server
|
||||
compute_services = [s for s in self.services.list()
|
||||
if s.binary == 'nova-compute']
|
||||
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
|
||||
.AndReturn(compute_services)
|
||||
api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, None,
|
||||
block_migration=False,
|
||||
disk_over_commit=False) \
|
||||
.AndReturn([])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_service_list.return_value = compute_services
|
||||
self.mock_server_live_migrate.return_value = []
|
||||
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
res = self.client.post(url, {'host': host, 'instance_id': server.id})
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.nova: ('service_list',
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_service_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), binary='nova-compute')
|
||||
self.mock_server_live_migrate(
|
||||
test.IsHttpRequest(), server.id, None,
|
||||
block_migration=False,
|
||||
disk_over_commit=False)
|
||||
|
||||
@test.create_mocks({api.nova: ['service_list',
|
||||
'server_get',
|
||||
'server_live_migrate',)})
|
||||
'server_live_migrate']})
|
||||
def test_instance_live_migrate_post_api_exception(self):
|
||||
server = self.servers.first()
|
||||
compute_services = [s for s in self.services.list()
|
||||
if s.binary == 'nova-compute']
|
||||
host = compute_services[0].host
|
||||
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndReturn(server)
|
||||
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
|
||||
.AndReturn(compute_services)
|
||||
api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, host,
|
||||
block_migration=False,
|
||||
disk_over_commit=False) \
|
||||
.AndRaise(self.exceptions.nova)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.return_value = server
|
||||
self.mock_service_list.return_value = compute_services
|
||||
self.mock_server_live_migrate.side_effect = self.exceptions.nova
|
||||
|
||||
url = reverse('horizon:admin:instances:live_migrate',
|
||||
args=[server.id])
|
||||
res = self.client.post(url, {'host': host, 'instance_id': server.id})
|
||||
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.nova: ('server_get',)})
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
self.mock_service_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), binary='nova-compute')
|
||||
self.mock_server_live_migrate.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id, host,
|
||||
block_migration=False,
|
||||
disk_over_commit=False)
|
||||
|
||||
@test.create_mocks({api.nova: ['server_get']})
|
||||
def test_instance_details_exception(self):
|
||||
server = self.servers.first()
|
||||
|
||||
api.nova.server_get(IsA(http.HttpRequest), server.id) \
|
||||
.AndRaise(self.exceptions.nova)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_server_get.side_effect = self.exceptions.nova
|
||||
|
||||
url = reverse('horizon:admin:instances:detail',
|
||||
args=[server.id])
|
||||
@ -428,6 +459,9 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
self.mock_server_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), server.id)
|
||||
|
||||
@test.update_settings(FILTER_DATA_FIRST={'admin.instances': True})
|
||||
def test_index_with_admin_filter_first(self):
|
||||
res = self.client.get(INDEX_URL)
|
||||
|
Loading…
Reference in New Issue
Block a user