def test_launch_keypairlist_error(self):
        IMAGE_ID = '2'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_images_launch',
                              args=[self.TEST_TENANT, IMAGE_ID]))

        self.assertTemplateUsed(res, 'dash_launch.html')

        form = res.context['form']

        form_keyfield = form.fields['key_name']
        self.assertEqual(len(form_keyfield.choices), 0)

        self.mox.VerifyAll()
    def test_index(self):
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_keypairs', args=[self.TEST_TENANT]))

        self.assertTemplateUsed(res, 'dash_keypairs.html')
        self.assertItemsEqual(res.context['keypairs'], self.keypairs)

        self.mox.VerifyAll()
    def test_index(self):
        self.mox.StubOutWithMock(api, "keypair_list")
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.ReplayAll()

        res = self.client.get(reverse("dash_keypairs", args=[self.TEST_TENANT]))

        self.assertTemplateUsed(res, "django_openstack/dash/keypairs/index.html")
        self.assertItemsEqual(res.context["keypairs"], self.keypairs)

        self.mox.VerifyAll()
Ejemplo n.º 4
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_keypairs',
                                      args=[self.TEST_TENANT]))

        self.assertTemplateUsed(res,
                                'django_openstack/dash/keypairs/index.html')
        self.assertItemsEqual(res.context['keypairs'], self.keypairs)

        self.mox.VerifyAll()
Ejemplo n.º 5
0
    def test_launch_get(self):
        IMAGE_ID = '1'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_images_launch',
                              args=[self.TEST_TENANT, IMAGE_ID]))

        self.assertTemplateUsed(res,
                'django_openstack/dash/images/launch.html')

        image = res.context['image']
        self.assertEqual(image.name, self.visibleImage.name)

        self.assertEqual(res.context['tenant'], self.TEST_TENANT)

        form = res.context['form']

        form_flavorfield = form.fields['flavor']
        self.assertIn('m1.massive', form_flavorfield.choices[0][1])

        form_keyfield = form.fields['key_name']
        self.assertEqual(form_keyfield.choices[0][0],
                         self.keypairs[0].name)

        self.mox.VerifyAll()
    def test_index_exception(self):
        exception = novaclient_exceptions.ClientException("clientException", message="clientException")
        self.mox.StubOutWithMock(api, "keypair_list")
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.StubOutWithMock(messages, "error")
        messages.error(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()

        res = self.client.get(reverse("dash_keypairs", args=[self.TEST_TENANT]))

        self.assertTemplateUsed(res, "django_openstack/dash/keypairs/index.html")
        self.assertEqual(len(res.context["keypairs"]), 0)

        self.mox.VerifyAll()
Ejemplo n.º 7
0
 def keynamelist():
     try:
         fl = api.keypair_list(request)
         sel = [(f.key_name, f.key_name) for f in fl]
         return sel
     except:
         return []
Ejemplo n.º 8
0
    def test_launch_get(self):
        IMAGE_ID = '1'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
            self.security_groups)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_images_launch', args=[self.TEST_TENANT, IMAGE_ID]))

        self.assertTemplateUsed(res,
                                'django_openstack/dash/images/launch.html')

        image = res.context['image']
        self.assertEqual(image.name, self.visibleImage.name)

        self.assertEqual(res.context['tenant'], self.TEST_TENANT)

        form = res.context['form']

        form_flavorfield = form.fields['flavor']
        self.assertIn('m1.massive', form_flavorfield.choices[0][1])

        form_keyfield = form.fields['key_name']
        self.assertEqual(form_keyfield.choices[0][0], self.keypairs[0].name)

        self.mox.VerifyAll()
Ejemplo n.º 9
0
 def keynamelist():
     try:
         fl = api.keypair_list(request)
         sel = [(f.name, f.name) for f in fl]
         return sel
     except api_exceptions.ApiException:
         LOG.exception('Unable to retrieve list of keypairs')
         return []
Ejemplo n.º 10
0
 def keynamelist():
     try:
         fl = api.keypair_list(request)
         sel = [(f.name, f.name) for f in fl]
         return sel
     except api_exceptions.ApiException:
         LOG.exception('Unable to retrieve list of keypairs')
         return []
    def test_index_exception(self):
        exception = api_exceptions.ApiException('apiException',
                                                message='apiException')
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_keypairs', args=[self.TEST_TENANT]))

        self.assertTemplateUsed(res, 'dash_keypairs.html')
        self.assertEqual(len(res.context['keypairs']), 0)

        self.mox.VerifyAll()
Ejemplo n.º 12
0
    def test_index_exception(self):
        exception = novaclient_exceptions.ClientException(
            'clientException', message='clientException')
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_keypairs',
                                      args=[self.TEST_TENANT]))

        self.assertTemplateUsed(res,
                                'django_openstack/dash/keypairs/index.html')
        self.assertEqual(len(res.context['keypairs']), 0)

        self.mox.VerifyAll()
Ejemplo n.º 13
0
def index(request, tenant_id):
    delete_form, handled = DeleteKeypair.maybe_handle(request)
    if handled:
        return handled

    try:
        keypairs = api.keypair_list(request)
    except api_exceptions.ApiException, e:
        keypairs = []
        messages.error(request, 'Error featching keypairs: %s' % e.message)
Ejemplo n.º 14
0
def index(request, tenant_id):
    delete_form, handled = DeleteKeypair.maybe_handle(request)

    if handled:
        return handled

    try:
        keypairs = api.keypair_list(request)
    except novaclient_exceptions.ClientException, e:
        keypairs = []
        LOG.exception("ClientException in keypair index")
        messages.error(request, _('Error fetching keypairs: %s') % e.message)
Ejemplo n.º 15
0
def index(request, tenant_id):
    delete_form, handled = DeleteKeypair.maybe_handle(request)

    if handled:
        return handled

    try:
        keypairs = api.keypair_list(request)
    except novaclient_exceptions.ClientException, e:
        keypairs = []
        LOG.exception("ClientException in keypair index")
        messages.error(request, _('Error fetching keypairs: %s') % e.message)
Ejemplo n.º 16
0
    def test_launch_flavorlist_error(self):
        IMAGE_ID = '1'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_images_launch',
                              args=[self.TEST_TENANT, IMAGE_ID]))

        self.assertTemplateUsed(res,
                'django_openstack/dash/images/launch.html')

        form = res.context['form']

        form_flavorfield = form.fields['flavor']
        self.assertIn('m1.tiny', form_flavorfield.choices[0][1])

        self.mox.VerifyAll()
Ejemplo n.º 17
0
    def test_launch_keypairlist_error(self):
        IMAGE_ID = '2'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
            self.security_groups)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_images_launch', args=[self.TEST_TENANT, IMAGE_ID]))

        self.assertTemplateUsed(res,
                                'django_openstack/dash/images/launch.html')

        form = res.context['form']

        form_keyfield = form.fields['key_name']
        self.assertEqual(len(form_keyfield.choices), 0)

        self.mox.VerifyAll()
Ejemplo n.º 18
0
    def test_keypair_list(self):
        novaclient = self.stub_novaclient()

        novaclient.keypairs = self.mox.CreateMockAnything()
        novaclient.keypairs.list().AndReturn(self.keypairs)

        self.mox.ReplayAll()

        ret_val = api.keypair_list(self.request)

        self.assertEqual(len(ret_val), len(self.keypairs))
        for keypair in ret_val:
            self.assertIsInstance(keypair, api.KeyPair)

        self.mox.VerifyAll()
Ejemplo n.º 19
0
    def test_keypair_list(self):
        NAME = 'keypair'
        keypairs = (NAME + '1', NAME + '2')

        extras_api = self.stub_extras_api()
        extras_api.keypairs = self.mox.CreateMockAnything()
        extras_api.keypairs.list().AndReturn(keypairs)

        self.mox.ReplayAll()

        ret_val = api.keypair_list(self.request)

        self.assertEqual(len(ret_val), len(keypairs))
        for keypair in ret_val:
            self.assertIsInstance(keypair, api.KeyPair)
            self.assertIn(keypair._apiresource, keypairs)

        self.mox.VerifyAll()
Ejemplo n.º 20
0
    def test_launch_form_apiexception(self):
        FLAVOR_ID = self.flavors[0].id
        IMAGE_ID = '1'
        KEY_NAME = self.keypairs[0].name
        SERVER_NAME = 'serverName'
        USER_DATA = 'userData'

        form_data = {'method': 'LaunchForm',
                     'flavor': FLAVOR_ID,
                     'image_id': IMAGE_ID,
                     'key_name': KEY_NAME,
                     'name': SERVER_NAME,
                     'tenant_id': self.TEST_TENANT,
                     'user_data': USER_DATA,
                     'security_groups': 'default',
                     }

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IgnoreArg(),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IgnoreArg(),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IgnoreArg()).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)

        # called again by the form
        api.image_get(IgnoreArg(),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'flavor_get')
        api.flavor_get(IgnoreArg(),
                       IsA(unicode)).AndReturn(self.flavors[0])

        self.mox.StubOutWithMock(api, 'server_create')

        exception = api_exceptions.ApiException('apiException')
        api.server_create(IsA(http.HttpRequest), SERVER_NAME,
                          self.visibleImage, self.flavors[0],
                          KEY_NAME, USER_DATA,
                          self.security_groups).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()
        url = reverse('dash_images_launch',
                      args=[self.TEST_TENANT, IMAGE_ID])
        res = self.client.post(url, form_data)

        self.assertTemplateUsed(res,
                'django_openstack/dash/images/launch.html')

        self.mox.VerifyAll()
Ejemplo n.º 21
0
    def test_launch_post(self):
        FLAVOR_ID = self.flavors[0].id
        IMAGE_ID = '1'
        KEY_NAME = self.keypairs[0].name
        SERVER_NAME = 'serverName'
        USER_DATA = 'userData'

        form_data = {'method': 'LaunchForm',
                     'flavor': FLAVOR_ID,
                     'image_id': IMAGE_ID,
                     'key_name': KEY_NAME,
                     'name': SERVER_NAME,
                     'user_data': USER_DATA,
                     'tenant_id': self.TEST_TENANT,
                     'security_groups': 'default',
                     }

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)

        # called again by the form
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'flavor_get')
        api.flavor_get(IsA(http.HttpRequest),
                       IsA(unicode)).AndReturn(self.flavors[0])

        self.mox.StubOutWithMock(api, 'server_create')

        api.server_create(IsA(http.HttpRequest), SERVER_NAME,
                          self.visibleImage, self.flavors[0],
                          KEY_NAME, USER_DATA, [self.security_groups[0].name])

        self.mox.StubOutWithMock(messages, 'success')
        messages.success(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()

        res = self.client.post(reverse('dash_images_launch',
                                        args=[self.TEST_TENANT, IMAGE_ID]),
                               form_data)

        self.assertRedirectsNoFollow(res, reverse('dash_instances',
                                          args=[self.TEST_TENANT]))

        self.mox.VerifyAll()
Ejemplo n.º 22
0
    def test_launch_post(self):
        FLAVOR_ID = self.flavors[0].id
        IMAGE_ID = '1'
        KEY_NAME = self.keypairs[0].name
        SERVER_NAME = 'serverName'
        USER_DATA = 'userData'

        form_data = {
            'method': 'LaunchForm',
            'flavor': FLAVOR_ID,
            'image_id': IMAGE_ID,
            'key_name': KEY_NAME,
            'name': SERVER_NAME,
            'user_data': USER_DATA,
            'tenant_id': self.TEST_TENANT,
            'security_groups': 'default',
        }

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
            self.security_groups)

        # called again by the form
        api.image_get(IsA(http.HttpRequest),
                      IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'flavor_get')
        api.flavor_get(IsA(http.HttpRequest),
                       IsA(unicode)).AndReturn(self.flavors[0])

        self.mox.StubOutWithMock(api, 'server_create')

        api.server_create(IsA(http.HttpRequest), SERVER_NAME,
                          self.visibleImage, self.flavors[0], KEY_NAME,
                          USER_DATA, [self.security_groups[0].name])

        self.mox.StubOutWithMock(messages, 'success')
        messages.success(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('dash_images_launch', args=[self.TEST_TENANT, IMAGE_ID]),
            form_data)

        self.assertRedirectsNoFollow(
            res, reverse('dash_instances', args=[self.TEST_TENANT]))

        self.mox.VerifyAll()
Ejemplo n.º 23
0
    def test_launch_form_apiexception(self):
        FLAVOR_ID = self.flavors[0].id
        IMAGE_ID = '1'
        KEY_NAME = self.keypairs[0].name
        SERVER_NAME = 'serverName'
        USER_DATA = 'userData'

        form_data = {
            'method': 'LaunchForm',
            'flavor': FLAVOR_ID,
            'image_id': IMAGE_ID,
            'key_name': KEY_NAME,
            'name': SERVER_NAME,
            'tenant_id': self.TEST_TENANT,
            'user_data': USER_DATA,
            'security_groups': 'default',
        }

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'token_get_tenant')
        api.token_get_tenant(IgnoreArg(),
                             self.TEST_TENANT).AndReturn(self.TEST_TENANT)

        self.mox.StubOutWithMock(api, 'tenant_quota_get')
        api.tenant_quota_get(IsA(http.HttpRequest),
                             self.TEST_TENANT).AndReturn(FakeQuota)

        self.mox.StubOutWithMock(api, 'flavor_list')
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors)

        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IgnoreArg()).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
            self.security_groups)

        # called again by the form
        api.image_get(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage)

        self.mox.StubOutWithMock(api, 'flavor_get')
        api.flavor_get(IgnoreArg(), IsA(unicode)).AndReturn(self.flavors[0])

        self.mox.StubOutWithMock(api, 'server_create')

        exception = api_exceptions.ApiException('apiException')
        api.server_create(IsA(http.HttpRequest), SERVER_NAME,
                          self.visibleImage, self.flavors[0], KEY_NAME,
                          USER_DATA, self.security_groups).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(str))

        self.mox.ReplayAll()
        url = reverse('dash_images_launch', args=[self.TEST_TENANT, IMAGE_ID])
        res = self.client.post(url, form_data)

        self.assertTemplateUsed(res,
                                'django_openstack/dash/images/launch.html')

        self.mox.VerifyAll()