예제 #1
0
파일: test_volume.py 프로젝트: zzxwill/heat
    def test_volume_detachment_err(self):
        stack_name = 'test_volume_detach_err_stack'

        self._mock_create_volume(vt_base.FakeVolume('creating'),
                                 stack_name)
        fva = self._mock_create_server_volume_script(
            vt_base.FakeVolume('attaching'))
        self.stub_VolumeConstraint_validate()
        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)

        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception(400))
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available', id=fva.id))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(
            u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())
        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'DataVolume')
        rsrc = self.create_attachment(self.t, stack, 'MountPoint')

        scheduler.TaskRunner(rsrc.delete)()

        self.m.VerifyAll()
    def _test_instance_create_delete(self, vm_status='ACTIVE',
                                     vm_delete_status='NotFound'):
        return_server = self.fc.servers.list()[1]
        instance = self._create_test_instance(return_server, 'in_create')

        instance.resource_id = '1234'
        instance.status = vm_status
        # this makes sure the auto increment worked on instance creation
        self.assertTrue(instance.id > 0)

        expected_ip = return_server.networks['public'][0]
        self.assertEqual(expected_ip, instance.FnGetAtt('PublicIp'))
        self.assertEqual(expected_ip, instance.FnGetAtt('PrivateIp'))
        self.assertEqual(expected_ip, instance.FnGetAtt('PrivateDnsName'))
        self.assertEqual(expected_ip, instance.FnGetAtt('PublicDnsName'))

        d1 = {'server': self.fc.client.get_servers_detail()[1]['servers'][0]}
        d1['server']['status'] = vm_status

        self.m.StubOutWithMock(self.fc.client, 'get_servers_1234')
        get = self.fc.client.get_servers_1234
        get().AndReturn((200, d1))

        d2 = copy.deepcopy(d1)
        if vm_delete_status == 'DELETED':
            d2['server']['status'] = vm_delete_status
            get().AndReturn((200, d2))
        else:
            get().AndRaise(fakes_nova.fake_exception())

        self.m.ReplayAll()

        scheduler.TaskRunner(instance.delete)()
        self.assertEqual((instance.DELETE, instance.COMPLETE), instance.state)
        self.m.VerifyAll()
예제 #3
0
    def _test_instance_create_delete(self, vm_status='ACTIVE',
                                     vm_delete_status='NotFound'):
        return_server = self.fc.servers.list()[1]
        instance = self._create_test_instance(return_server, 'in_create')

        instance.resource_id = '1234'
        instance.status = vm_status
        # this makes sure the auto increment worked on instance creation
        self.assertTrue(instance.id > 0)

        expected_ip = return_server.networks['public'][0]
        self.assertEqual(expected_ip, instance.FnGetAtt('PublicIp'))
        self.assertEqual(expected_ip, instance.FnGetAtt('PrivateIp'))
        self.assertEqual(expected_ip, instance.FnGetAtt('PrivateDnsName'))
        self.assertEqual(expected_ip, instance.FnGetAtt('PublicDnsName'))

        d1 = {'server': self.fc.client.get_servers_detail()[1]['servers'][0]}
        d1['server']['status'] = vm_status

        self.m.StubOutWithMock(self.fc.client, 'get_servers_1234')
        get = self.fc.client.get_servers_1234
        get().AndReturn((200, d1))

        d2 = copy.deepcopy(d1)
        if vm_delete_status == 'DELETED':
            d2['server']['status'] = vm_delete_status
            get().AndReturn((200, d2))
        else:
            get().AndRaise(fakes_nova.fake_exception())

        self.m.ReplayAll()

        scheduler.TaskRunner(instance.delete)()
        self.assertEqual((instance.DELETE, instance.COMPLETE), instance.state)
        self.m.VerifyAll()
예제 #4
0
    def test_volume_detach_non_exist(self):
        fv = vt_base.FakeVolume('creating')
        fva = vt_base.FakeVolume('in-use')
        stack_name = 'test_volume_detach_nonexist_stack'

        self._mock_create_volume(fv, stack_name)
        self._mock_create_server_volume_script(fva)
        self.stub_VolumeConstraint_validate()
        # delete script
        self.fc.volumes.delete_server_volume(u'WikiDatabase',
                                             'vol-123').AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndRaise(
            cinder_exp.NotFound('Not found'))
        self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise(
            fakes_nova.fake_exception())

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'DataVolume')
        rsrc = self.create_attachment(self.t, stack, 'MountPoint')

        scheduler.TaskRunner(rsrc.delete)()

        self.m.VerifyAll()
예제 #5
0
    def test_503_error(self):
        server = self.m.CreateMockAnything()
        server.get().AndRaise(fakes_nova.fake_exception(503))
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
예제 #6
0
    def test_cinder_attachment_no_mountpoint(self):
        stack_name = 'test_cvolume_attach_stack'

        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)
        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'),
                                               device=None)
        self.stub_VolumeConstraint_validate()

        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise(
            fakes_nova.fake_exception())

        self.m.ReplayAll()

        self.t['resources']['attachment']['properties']['mountpoint'] = ''
        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'volume')
        rsrc = self.create_attachment(self.t, stack, 'attachment')

        scheduler.TaskRunner(rsrc.delete)()

        self.m.VerifyAll()
예제 #7
0
    def test_cinder_attachment_no_mountpoint(self):
        stack_name = 'test_cvolume_attach_stack'

        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)
        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'),
                                               device=None)
        self.stub_VolumeConstraint_validate()

        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(
            u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())

        self.m.ReplayAll()

        self.t['resources']['attachment']['properties']['mountpoint'] = ''
        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'volume')
        rsrc = self.create_attachment(self.t, stack, 'attachment')

        scheduler.TaskRunner(rsrc.delete)()

        self.m.VerifyAll()
예제 #8
0
    def test_wordpress_single_instance_stack_delete(self):
        ctx = utils.dummy_context()
        stack = tools.get_stack("test_stack", ctx)
        fc = tools.setup_mocks(self.m, stack, mock_keystone=False)
        self.m.ReplayAll()
        stack_id = stack.store()
        stack.create()

        db_s = stack_object.Stack.get_by_id(ctx, stack_id)
        self.assertIsNotNone(db_s)

        self.assertIsNotNone(stack["WebServer"])
        self.assertTrue(int(stack["WebServer"].resource_id) > 0)

        self.patchobject(fc.servers, "delete", side_effect=fakes_nova.fake_exception())
        stack.delete()

        rsrc = stack["WebServer"]
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
        self.assertEqual((stack.DELETE, stack.COMPLETE), rsrc.state)
        self.assertIsNone(stack_object.Stack.get_by_id(ctx, stack_id))

        db_s.refresh()
        self.assertEqual("DELETE", db_s.action)
        self.assertEqual("COMPLETE", db_s.status)
    def test_delete_association_successful_if_create_failed(self):
        server = self.fc.servers.list()[0]
        self._mock_server_get(mock_server=server, multiple=True)
        self.m.StubOutWithMock(self.fc.servers, 'add_floating_ip')
        self.fc.servers.add_floating_ip(server, '11.0.0.1').AndRaise(
            fakes_nova.fake_exception(400))
        self.m.ReplayAll()

        t = template_format.parse(eip_template_ipassoc)
        stack = utils.parse_stack(t)

        self.create_eip(t, stack, 'IPAddress')
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = eip.ElasticIpAssociation('IPAssoc',
                                        resource_defns['IPAssoc'],
                                        stack)
        self.assertIsNone(rsrc.validate())
        self.assertRaises(exception.ResourceFailure,
                          scheduler.TaskRunner(rsrc.create))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)

        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
예제 #10
0
 def test_sg_delete_not_found(self):
     self._create_sg('test')
     self.sg_mgr.delete.side_effect = fakes_nova.fake_exception()
     scheduler.TaskRunner(self.sg.delete)()
     self.sg_mgr.delete.assert_called_once_with('test')
     self.assertEqual((self.sg.DELETE, self.sg.COMPLETE),
                      self.sg.state)
예제 #11
0
 def test_sg_delete_not_found(self):
     self._create_sg('test')
     self.sg_mgr.delete.side_effect = fakes_nova.fake_exception()
     scheduler.TaskRunner(self.sg.delete)()
     self.sg_mgr.delete.assert_called_once_with('test')
     self.assertEqual((self.sg.DELETE, self.sg.COMPLETE),
                      self.sg.state)
예제 #12
0
파일: test_volume.py 프로젝트: sizowie/heat
    def test_volume_detach_non_exist(self):
        fv = vt_base.FakeVolume('creating')
        fva = vt_base.FakeVolume('in-use')
        stack_name = 'test_volume_detach_nonexist_stack'

        self._mock_create_volume(fv, stack_name)
        self._mock_create_server_volume_script(fva)
        self.stub_VolumeConstraint_validate()
        # delete script
        self.fc.volumes.delete_server_volume(u'WikiDatabase',
                                             'vol-123').AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndRaise(
            cinder_exp.NotFound('Not found'))
        self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123'
                                          ).AndRaise(
                                              fakes_nova.fake_exception())

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'DataVolume')
        rsrc = self.create_attachment(self.t, stack, 'MountPoint')

        scheduler.TaskRunner(rsrc.delete)()

        self.m.VerifyAll()
예제 #13
0
    def test_503_error(self):
        server = self.m.CreateMockAnything()
        server.get().AndRaise(fakes_nova.fake_exception(503))
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
예제 #14
0
    def create_delete_assoc_with_exc(self, exc_code):
        rsrc = self.prepare_floating_ip_assoc()
        self.novaclient.servers.add_floating_ip(None, '11.0.0.1')
        self.novaclient.servers.get(
            "67dc62f9-efde-4c8b-94af-013e00f5dc57").AndReturn("server")
        self.novaclient.floating_ips.get('1').AndReturn(
            self._make_obj(**{
                "id": "1",
                "ip": "11.0.0.1",
                "pool": "public"
            })
        )
        self.novaclient.servers.remove_floating_ip("server",
                                                   "11.0.0.1").AndRaise(
            fakes_nova.fake_exception(exc_code))

        self.m.ReplayAll()

        rsrc.validate()
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
예제 #15
0
    def test_cinder_volume_attachment_update_device(self):
        stack_name = "test_cvolume_attach_udev_stack"

        self._mock_create_volume(vt_base.FakeVolume("creating"), stack_name)
        self._mock_create_server_volume_script(vt_base.FakeVolume("attaching"))
        self.stub_VolumeConstraint_validate()

        # delete script
        fva = vt_base.FakeVolume("in-use")
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume("WikiDatabase", "vol-123").MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(vt_base.FakeVolume("available"))
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndReturn(fva)
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndRaise(fakes_nova.fake_exception())

        # attach script
        self._mock_create_server_volume_script(vt_base.FakeVolume("attaching"), device=u"/dev/vdd", update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, "volume")
        rsrc = self.create_attachment(self.t, stack, "attachment")

        props = copy.deepcopy(rsrc.properties.data)
        props["mountpoint"] = "/dev/vdd"
        props["volume_id"] = "vol-123"
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
        scheduler.TaskRunner(rsrc.update, after)()

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
예제 #16
0
    def test_volume_detach_with_latency(self):
        stack_name = "test_volume_detach_latency_stack"

        self._mock_create_volume(vt_base.FakeVolume("creating"), stack_name)
        fva = self._mock_create_server_volume_script(vt_base.FakeVolume("attaching"))
        self.stub_VolumeConstraint_validate()

        # delete script
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume("WikiDatabase", "vol-123").MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(vt_base.FakeVolume("in-use", id=fva.id))
        self.cinder_fc.volumes.get(fva.id).AndReturn(vt_base.FakeVolume("detaching", id=fva.id))
        self.cinder_fc.volumes.get(fva.id).AndReturn(vt_base.FakeVolume("available", id=fva.id))
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndReturn(fva)
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndRaise(fakes_nova.fake_exception())

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, "DataVolume")
        rsrc = self.create_attachment(self.t, stack, "MountPoint")

        scheduler.TaskRunner(rsrc.delete)()

        self.m.VerifyAll()
예제 #17
0
파일: test_volume.py 프로젝트: sizowie/heat
    def test_cinder_volume_extend_attached(self):
        stack_name = 'test_cvolume_extend_att_stack'
        # create script
        self.stub_VolumeConstraint_validate()
        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)

        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'))

        # update script
        attachments = [{
            'id': 'vol-123',
            'device': '/dev/vdc',
            'server_id': u'WikiDatabase'
        }]
        fv2 = vt_base.FakeVolume('in-use', attachments=attachments, size=1)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)

        # detach script
        fvd = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fvd)
        self.cinder_fc.volumes.get(fvd.id).AndReturn(fvd)
        self.fc.volumes.delete_server_volume('WikiDatabase', 'vol-123')
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fvd)
        self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise(
            fakes_nova.fake_exception())

        # resize script
        self.cinder_fc.volumes.extend(fvd.id, 2)
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('extending'))
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('extending'))
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('available'))

        # attach script
        self._mock_create_server_volume_script(
            vt_base.FakeVolume('attaching'), update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        rsrc = self.create_volume(self.t, stack, 'volume')
        self.create_attachment(self.t, stack, 'attachment')

        props = copy.deepcopy(rsrc.properties.data)
        props['size'] = 2
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)

        update_task = scheduler.TaskRunner(rsrc.update, after)
        self.assertIsNone(update_task())

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
예제 #18
0
    def test_cinder_volume_extend_attached(self):
        stack_name = 'test_cvolume_extend_att_stack'
        # create script
        self.stub_VolumeConstraint_validate()
        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)

        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'))

        # update script
        attachments = [{
            'id': 'vol-123',
            'device': '/dev/vdc',
            'server_id': u'WikiDatabase'
        }]
        fv2 = vt_base.FakeVolume('in-use', attachments=attachments, size=1)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)

        # detach script
        fvd = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fvd)
        self.cinder_fc.volumes.get(fvd.id).AndReturn(fvd)
        self.fc.volumes.delete_server_volume('WikiDatabase', 'vol-123')
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fvd)
        self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise(
            fakes_nova.fake_exception())

        # resize script
        self.cinder_fc.volumes.extend(fvd.id, 2)
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('extending'))
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('extending'))
        self.cinder_fc.volumes.get(fvd.id).AndReturn(
            vt_base.FakeVolume('available'))

        # attach script
        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'),
                                               update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        rsrc = self.create_volume(self.t, stack, 'volume')
        self.create_attachment(self.t, stack, 'attachment')

        props = copy.deepcopy(rsrc.properties.data)
        props['size'] = 2
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)

        update_task = scheduler.TaskRunner(rsrc.update, after)
        self.assertIsNone(update_task())

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
예제 #19
0
    def test_unhandled_exception(self):
        server = self.m.CreateMockAnything()
        server.get().AndRaise(fakes_nova.fake_exception(501))
        self.m.ReplayAll()

        self.assertRaises(nova_exceptions.ClientException,
                          nova_utils.refresh_server, server)
        self.m.VerifyAll()
예제 #20
0
    def test_unhandled_exception(self):
        server = self.m.CreateMockAnything()
        server.get().AndRaise(fakes_nova.fake_exception(501))
        self.m.ReplayAll()

        self.assertRaises(nova_exceptions.ClientException,
                          nova_utils.refresh_server, server)
        self.m.VerifyAll()
예제 #21
0
 def test_flavor_handle_delete(self):
     self.resource_id = None
     self.assertIsNone(self.my_flavor.handle_delete())
     flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'
     self.my_flavor.resource_id = flavor_id
     self.flavors.delete.return_value = None
     self.assertIsNone(self.my_flavor.handle_delete())
     self.flavors.delete.side_effect = fakes.fake_exception()
     self.assertIsNone(self.my_flavor.handle_delete())
예제 #22
0
 def test_flavor_handle_delete(self):
     self.resource_id = None
     self.assertIsNone(self.my_flavor.handle_delete())
     flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'
     self.my_flavor.resource_id = flavor_id
     self.flavors.delete.return_value = None
     self.assertIsNone(self.my_flavor.handle_delete())
     self.flavors.delete.side_effect = fakes.fake_exception()
     self.assertIsNone(self.my_flavor.handle_delete())
예제 #23
0
    def test_cinder_volume_attachment_update_volume(self):
        stack_name = 'test_cvolume_attach_uvol_stack'

        self.stub_VolumeConstraint_validate()
        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)

        fv2 = vt_base.FakeVolume('creating', id='vol-456')
        vol2_name = utils.PhysName(stack_name, 'volume2')
        self.cinder_fc.volumes.create(size=2,
                                      availability_zone='nova',
                                      description=None,
                                      name=vol2_name).AndReturn(fv2)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)
        fv2 = vt_base.FakeVolume('available', id=fv2.id)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)

        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'))

        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise(
            fakes_nova.fake_exception())

        # attach script
        fv2a = vt_base.FakeVolume('attaching', id='vol-456')
        self._mock_create_server_volume_script(fv2a,
                                               volume='vol-456',
                                               update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'volume')
        self.create_volume(self.t, stack, 'volume2')

        rsrc = self.create_attachment(self.t, stack, 'attachment')
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

        props = copy.deepcopy(rsrc.properties.data)
        props['volume_id'] = 'vol-456'
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
        scheduler.TaskRunner(rsrc.update, after)()

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.assertEqual(fv2a.id, rsrc.resource_id)
        self.m.VerifyAll()
예제 #24
0
파일: test_volume.py 프로젝트: aawm/heat
    def test_cinder_volume_attachment_update_volume(self):
        stack_name = 'test_cvolume_attach_uvol_stack'

        self.stub_VolumeConstraint_validate()
        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)

        fv2 = vt_base.FakeVolume('creating', id='vol-456')
        vol2_name = utils.PhysName(stack_name, 'volume2')
        self.cinder_fc.volumes.create(
            size=2, availability_zone='nova',
            description=None,
            name=vol2_name).AndReturn(fv2)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)
        fv2 = vt_base.FakeVolume('available', id=fv2.id)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)

        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'))

        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(
            u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())

        # attach script
        fv2a = vt_base.FakeVolume('attaching', id='vol-456')
        self._mock_create_server_volume_script(fv2a, volume='vol-456',
                                               update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'volume')
        self.create_volume(self.t, stack, 'volume2')

        rsrc = self.create_attachment(self.t, stack, 'attachment')
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

        props = copy.deepcopy(rsrc.properties.data)
        props['volume_id'] = 'vol-456'
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
        scheduler.TaskRunner(rsrc.update, after)()

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.assertEqual(fv2a.id, rsrc.resource_id)
        self.m.VerifyAll()
예제 #25
0
 def test_delete_key_not_found(self):
     """Test delete non-existent key."""
     test_res = self._get_test_resource(self.kp_template)
     test_res.resource_id = "key_name"
     test_res.state_set(test_res.CREATE, test_res.COMPLETE)
     (self.fake_keypairs.delete("key_name").AndRaise(
         fakes_nova.fake_exception()))
     self.m.ReplayAll()
     scheduler.TaskRunner(test_res.delete)()
     self.assertEqual((test_res.DELETE, test_res.COMPLETE), test_res.state)
     self.m.VerifyAll()
예제 #26
0
 def test_delete_key_not_found(self):
     """Test delete non-existent key."""
     test_res = self._get_test_resource(self.kp_template)
     test_res.resource_id = "key_name"
     test_res.state_set(test_res.CREATE, test_res.COMPLETE)
     (self.fake_keypairs.delete("key_name")
         .AndRaise(fakes_nova.fake_exception()))
     self.m.ReplayAll()
     scheduler.TaskRunner(test_res.delete)()
     self.assertEqual((test_res.DELETE, test_res.COMPLETE), test_res.state)
     self.m.VerifyAll()
예제 #27
0
파일: tools.py 프로젝트: james49/heat
def clean_up_stack(stack, delete_res=True):
    if delete_res:
        m = mox.Mox()
        fc = fakes_nova.FakeClient()
        m.StubOutWithMock(instances.Instance, "client")
        instances.Instance.client().MultipleTimes().AndReturn(fc)
        m.StubOutWithMock(fc.servers, "delete")
        fc.servers.delete(mox.IgnoreArg()).AndRaise(fakes_nova.fake_exception())
        m.ReplayAll()
    stack.delete()
    if delete_res:
        m.UnsetStubs()
예제 #28
0
def clean_up_stack(stack, delete_res=True):
    if delete_res:
        m = mox.Mox()
        fc = fakes_nova.FakeClient()
        m.StubOutWithMock(instances.Instance, 'nova')
        instances.Instance.nova().MultipleTimes().AndReturn(fc)
        m.StubOutWithMock(fc.client, 'get_servers_9999')
        get = fc.client.get_servers_9999
        get().AndRaise(fakes_nova.fake_exception())
        m.ReplayAll()
    stack.delete()
    if delete_res:
        m.UnsetStubs()
예제 #29
0
def clean_up_stack(stack, delete_res=True):
    if delete_res:
        m = mox.Mox()
        fc = fakes_nova.FakeClient()
        m.StubOutWithMock(instances.Instance, 'client')
        instances.Instance.client().MultipleTimes().AndReturn(fc)
        m.StubOutWithMock(fc.servers, 'delete')
        fc.servers.delete(mox.IgnoreArg()).AndRaise(
            fakes_nova.fake_exception())
        m.ReplayAll()
    stack.delete()
    if delete_res:
        m.UnsetStubs()
예제 #30
0
    def test_eip_with_exception(self):
        self.m.StubOutWithMock(self.fc.floating_ips, 'create')
        nova.NovaClientPlugin._create().AndReturn(self.fc)
        self.fc.floating_ips.create().AndRaise(fakes_nova.fake_exception())
        self.m.ReplayAll()

        t = template_format.parse(eip_template)
        stack = utils.parse_stack(t)
        resource_name = 'IPAddress'
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = eip.ElasticIp(resource_name, resource_defns[resource_name],
                             stack)

        self.assertRaises(nova_exceptions.NotFound, rsrc.handle_create)
        self.m.VerifyAll()
예제 #31
0
    def test_delete_floating_ip_assoc_successful_if_create_failed(self):
        rsrc = self.prepare_floating_ip_assoc()
        self.novaclient.servers.add_floating_ip(None, '11.0.0.1').AndRaise(
            fakes_nova.fake_exception(400))

        self.m.ReplayAll()

        rsrc.validate()

        self.assertRaises(heat_ex.ResourceFailure,
                          scheduler.TaskRunner(rsrc.create))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
예제 #32
0
    def test_delete_floating_ip_assoc_successful_if_create_failed(self):
        rsrc = self.prepare_floating_ip_assoc()
        self.novaclient.servers.add_floating_ip(None, '11.0.0.1').AndRaise(
            fakes_nova.fake_exception(400))

        self.m.ReplayAll()

        rsrc.validate()

        self.assertRaises(heat_ex.ResourceFailure,
                          scheduler.TaskRunner(rsrc.create))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
예제 #33
0
    def test_cinder_volume_extend_attached(self):
        stack_name = "test_cvolume_extend_att_stack"
        # create script
        self.stub_VolumeConstraint_validate()
        self._mock_create_volume(vt_base.FakeVolume("creating"), stack_name)

        self._mock_create_server_volume_script(vt_base.FakeVolume("attaching"))

        # update script
        attachments = [{"id": "vol-123", "device": "/dev/vdc", "server_id": u"WikiDatabase"}]
        fv2 = vt_base.FakeVolume("in-use", attachments=attachments, size=1)
        self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2)

        # detach script
        fvd = vt_base.FakeVolume("in-use")
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndReturn(fvd)
        self.cinder_fc.volumes.get(fvd.id).AndReturn(fvd)
        self.fc.volumes.delete_server_volume("WikiDatabase", "vol-123")
        self.cinder_fc.volumes.get(fvd.id).AndReturn(vt_base.FakeVolume("available"))
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndReturn(fvd)
        self.fc.volumes.get_server_volume(u"WikiDatabase", "vol-123").AndRaise(fakes_nova.fake_exception())

        # resize script
        self.cinder_fc.volumes.extend(fvd.id, 2)
        self.cinder_fc.volumes.get(fvd.id).AndReturn(vt_base.FakeVolume("extending"))
        self.cinder_fc.volumes.get(fvd.id).AndReturn(vt_base.FakeVolume("extending"))
        self.cinder_fc.volumes.get(fvd.id).AndReturn(vt_base.FakeVolume("available"))

        # attach script
        self._mock_create_server_volume_script(vt_base.FakeVolume("attaching"), update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        rsrc = self.create_volume(self.t, stack, "volume")
        self.create_attachment(self.t, stack, "attachment")

        props = copy.deepcopy(rsrc.properties.data)
        props["size"] = 2
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)

        update_task = scheduler.TaskRunner(rsrc.update, after)
        self.assertIsNone(update_task())

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
예제 #34
0
 def test_get_keypair(self):
     """Tests the get_keypair function."""
     my_pub_key = 'a cool public key string'
     my_key_name = 'mykey'
     my_key = self.m.CreateMockAnything()
     my_key.public_key = my_pub_key
     my_key.name = my_key_name
     self.nova_client.keypairs = self.m.CreateMockAnything()
     self.nova_client.keypairs.get(my_key_name).AndReturn(my_key)
     self.nova_client.keypairs.get('notakey').AndRaise(
         fakes_nova.fake_exception())
     self.m.ReplayAll()
     self.assertEqual(my_key,
                      nova_utils.get_keypair(self.nova_client, my_key_name))
     self.assertRaises(exception.UserKeyPairMissing, nova_utils.get_keypair,
                       self.nova_client, 'notakey')
     self.m.VerifyAll()
예제 #35
0
    def test_delete_eip_with_exception(self):
        self.m.StubOutWithMock(self.fc.floating_ips, 'delete')
        nova.NovaClientPlugin._create().AndReturn(self.fc)
        self.fc.floating_ips.delete(mox.IsA(object)).AndRaise(
            fakes_nova.fake_exception())
        self.fc.servers.get(mox.IsA(object)).AndReturn(False)
        self.m.ReplayAll()

        t = template_format.parse(eip_template)
        stack = utils.parse_stack(t)
        resource_name = 'IPAddress'
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = eip.ElasticIp(resource_name, resource_defns[resource_name],
                             stack)
        rsrc.resource_id = 'fake_id'
        rsrc.handle_delete()
        self.m.VerifyAll()
    def test_eip_with_exception(self):
        self.m.StubOutWithMock(self.fc.floating_ips, 'create')
        nova.NovaClientPlugin._create().AndReturn(self.fc)
        self.fc.floating_ips.create().AndRaise(fakes_nova.fake_exception())
        self.m.ReplayAll()

        t = template_format.parse(eip_template)
        stack = utils.parse_stack(t)
        resource_name = 'IPAddress'
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = eip.ElasticIp(resource_name,
                             resource_defns[resource_name],
                             stack)

        self.assertRaises(nova_exceptions.NotFound,
                          rsrc.handle_create)
        self.m.VerifyAll()
예제 #37
0
    def test_validation(self):
        client = fakes_nova.FakeClient()
        self.patchobject(nova.NovaClientPlugin, '_create', return_value=client)
        client.keypairs = mock.MagicMock()

        key = collections.namedtuple("Key", ["name"])
        key.name = "foo"
        client.keypairs.get.side_effect = [fakes_nova.fake_exception(), key]

        constraint = nova.KeypairConstraint()
        ctx = utils.dummy_context()
        self.assertFalse(constraint.validate("bar", ctx))
        self.assertTrue(constraint.validate("foo", ctx))
        self.assertTrue(constraint.validate("", ctx))
        nova.NovaClientPlugin._create.assert_called_once_with()
        calls = [mock.call('bar'), mock.call(key.name)]
        client.keypairs.get.assert_has_calls(calls)
    def test_delete_eip_with_exception(self):
        self.m.StubOutWithMock(self.fc.floating_ips, 'delete')
        nova.NovaClientPlugin._create().AndReturn(self.fc)
        self.fc.floating_ips.delete(mox.IsA(object)).AndRaise(
            fakes_nova.fake_exception())
        self.fc.servers.get(mox.IsA(object)).AndReturn(False)
        self.m.ReplayAll()

        t = template_format.parse(eip_template)
        stack = utils.parse_stack(t)
        resource_name = 'IPAddress'
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = eip.ElasticIp(resource_name,
                             resource_defns[resource_name],
                             stack)
        rsrc.resource_id = 'fake_id'
        rsrc.handle_delete()
        self.m.VerifyAll()
예제 #39
0
 def test_get_keypair(self):
     """Tests the get_keypair function."""
     my_pub_key = 'a cool public key string'
     my_key_name = 'mykey'
     my_key = self.m.CreateMockAnything()
     my_key.public_key = my_pub_key
     my_key.name = my_key_name
     self.nova_client.keypairs = self.m.CreateMockAnything()
     self.nova_client.keypairs.get(
         my_key_name).AndReturn(my_key)
     self.nova_client.keypairs.get(
         'notakey').AndRaise(fakes_nova.fake_exception())
     self.m.ReplayAll()
     self.assertEqual(my_key, nova_utils.get_keypair(self.nova_client,
                                                     my_key_name))
     self.assertRaises(exception.UserKeyPairMissing, nova_utils.get_keypair,
                       self.nova_client, 'notakey')
     self.m.VerifyAll()
예제 #40
0
파일: test_volume.py 프로젝트: aawm/heat
    def test_cinder_volume_attachment_update_server(self):
        stack_name = 'test_cvolume_attach_usrv_stack'

        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)
        self._mock_create_server_volume_script(
            vt_base.FakeVolume('attaching'))
        self.stub_VolumeConstraint_validate()

        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(
            u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())

        # attach script
        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'),
                                               server=u'AnotherServer',
                                               update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'volume')

        rsrc = self.create_attachment(self.t, stack, 'attachment')
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

        props = copy.deepcopy(rsrc.properties.data)
        props['instance_uuid'] = 'AnotherServer'
        props['volume_id'] = 'vol-123'
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
        scheduler.TaskRunner(rsrc.update, after)()

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
예제 #41
0
    def test_cinder_volume_attachment_update_server(self):
        stack_name = 'test_cvolume_attach_usrv_stack'

        self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name)
        self._mock_create_server_volume_script(
            vt_base.FakeVolume('attaching'))
        self.stub_VolumeConstraint_validate()

        # delete script
        fva = vt_base.FakeVolume('in-use')
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
        self.fc.volumes.delete_server_volume(
            'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
        self.cinder_fc.volumes.get(fva.id).AndReturn(
            vt_base.FakeVolume('available'))
        self.fc.volumes.get_server_volume(u'WikiDatabase',
                                          'vol-123').AndReturn(fva)
        self.fc.volumes.get_server_volume(
            u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())

        # attach script
        self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'),
                                               server=u'AnotherServer',
                                               update=True)

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'volume')

        rsrc = self.create_attachment(self.t, stack, 'attachment')
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

        props = copy.deepcopy(rsrc.properties.data)
        props['instance_uuid'] = 'AnotherServer'
        props['volume_id'] = 'vol-123'
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
        scheduler.TaskRunner(rsrc.update, after)()

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()
예제 #42
0
    def test_validation(self):
        client = fakes_nova.FakeClient()
        self.patchobject(nova.NovaClientPlugin, '_create', return_value=client)
        client.keypairs = mock.MagicMock()

        key = collections.namedtuple("Key", ["name"])
        key.name = "foo"
        client.keypairs.get.side_effect = [
            fakes_nova.fake_exception(), key]

        constraint = nova.KeypairConstraint()
        ctx = utils.dummy_context()
        self.assertFalse(constraint.validate("bar", ctx))
        self.assertTrue(constraint.validate("foo", ctx))
        self.assertTrue(constraint.validate("", ctx))
        nova.NovaClientPlugin._create.assert_called_once_with()
        calls = [mock.call('bar'),
                 mock.call(key.name)]
        client.keypairs.get.assert_has_calls(calls)
예제 #43
0
    def test_stack_authorize_stack_user(self):
        self.ctx = utils.dummy_context()
        self.ctx.aws_creds = '{"ec2Credentials": {"access": "4567"}}'
        stack_name = "stack_authorize_stack_user"
        stack = tools.get_stack(stack_name, self.ctx, user_policy_template)
        self.stack = stack
        fc = tools.setup_mocks(self.m, stack)
        self.patchobject(fc.servers, "delete", side_effect=fakes_nova.fake_exception())

        self.m.ReplayAll()
        stack.store()
        stack.create()

        self.assertTrue(self.eng._authorize_stack_user(self.ctx, self.stack, "WebServer"))

        self.assertFalse(self.eng._authorize_stack_user(self.ctx, self.stack, "CfnUser"))

        self.assertFalse(self.eng._authorize_stack_user(self.ctx, self.stack, "NoSuchResource"))

        self.m.VerifyAll()
예제 #44
0
    def create_delete_assoc_with_exc(self, exc_code):
        rsrc = self.prepare_floating_ip_assoc()
        self.novaclient.servers.add_floating_ip(None, '11.0.0.1')
        self.novaclient.servers.get(
            "67dc62f9-efde-4c8b-94af-013e00f5dc57").AndReturn("server")
        self.novaclient.floating_ips.get('1').AndReturn(
            self._make_obj(**{
                "id": "1",
                "ip": "11.0.0.1",
                "pool": "public"
            }))
        self.novaclient.servers.remove_floating_ip(
            "server", "11.0.0.1").AndRaise(fakes_nova.fake_exception(exc_code))

        self.m.ReplayAll()

        rsrc.validate()
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
예제 #45
0
    def test_delete_association_successful_if_create_failed(self):
        server = self.fc.servers.list()[0]
        self._mock_server_get(mock_server=server, multiple=True)
        self.m.StubOutWithMock(self.fc.servers, 'add_floating_ip')
        self.fc.servers.add_floating_ip(server, '11.0.0.1').AndRaise(
            fakes_nova.fake_exception(400))
        self.m.ReplayAll()

        t = template_format.parse(eip_template_ipassoc)
        stack = utils.parse_stack(t)

        self.create_eip(t, stack, 'IPAddress')
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = eip.ElasticIpAssociation('IPAssoc', resource_defns['IPAssoc'],
                                        stack)
        self.assertIsNone(rsrc.validate())
        self.assertRaises(exception.ResourceFailure,
                          scheduler.TaskRunner(rsrc.create))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)

        scheduler.TaskRunner(rsrc.delete)()
        self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)

        self.m.VerifyAll()
예제 #46
0
 def test_overlimit_error(self):
     server = mock.Mock()
     server.get.side_effect = fakes_nova.fake_exception(413)
     self.assertIsNone(nova_utils.refresh_server(server))
예제 #47
0
 def test_overlimit_error(self):
     server = mock.Mock()
     server.get.side_effect = fakes_nova.fake_exception(413)
     self.assertIsNone(nova_utils.refresh_server(server))
예제 #48
0
    def test_security_group_nova_exception(self):
        # create script
        self.mock_no_neutron()
        nova.NovaClientPlugin._create().AndReturn(self.fc)
        sg_name = utils.PhysName('test_stack', 'the_sg')
        nova_sg.SecurityGroupManager.list().MultipleTimes().AndReturn([
            NovaSG(
                id=2,
                name=sg_name,
                description='HTTP and SSH access',
                rules=[],
            ),
            NovaSG(
                id=1,
                name='test',
                description='FAKE_SECURITY_GROUP',
                rules=[],
            )
        ])

        nova_sgr.SecurityGroupRuleManager.create(
            2, 'tcp', 22, 22, '0.0.0.0/0', None).AndRaise(
                fakes_nova.fake_exception(400, 'Rule already exists'))
        nova_sgr.SecurityGroupRuleManager.create(
            2, 'tcp', 80, 80, '0.0.0.0/0', None).AndReturn(
                fakes_nova.fake_exception(400, 'Rule already exists'))
        nova_sgr.SecurityGroupRuleManager.create(
            2, 'tcp', None, None, None, 1).AndReturn(
                fakes_nova.fake_exception(400, 'Rule already exists'))
        nova_sgr.SecurityGroupRuleManager.create(
            2, 'icmp', None, None, None, '1').AndReturn(
                fakes_nova.fake_exception(400, 'Rule already exists'))

        # delete script
        nova_sg.SecurityGroupManager.get(2).AndReturn(NovaSG(
            id=2,
            name=sg_name,
            description='HTTP and SSH access',
            rules=[{
                "from_port": 22,
                "group": {},
                "ip_protocol": "tcp",
                "to_port": 22,
                "parent_group_id": 2,
                "ip_range": {
                    "cidr": "0.0.0.0/0"
                },
                'id': 130
            }, {
                'from_port': 80,
                'group': {},
                'ip_protocol': 'tcp',
                'to_port': 80,
                'parent_group_id': 2,
                'ip_range': {
                    'cidr': '0.0.0.0/0'
                },
                'id': 131
            }, {
                'from_port': None,
                'group': {
                    'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
                    'name': 'test'
                },
                'ip_protocol': 'tcp',
                'to_port': None,
                'parent_group_id': 2,
                'ip_range': {},
                'id': 132
            }, {
                'from_port': None,
                'group': {
                    'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
                    'name': 'test'
                },
                'ip_protocol': 'icmp',
                'to_port': None,
                'parent_group_id': 2,
                'ip_range': {},
                'id': 133
            }]
        ))
        nova_sgr.SecurityGroupRuleManager.delete(130).AndRaise(
            fakes_nova.fake_exception())
        nova_sgr.SecurityGroupRuleManager.delete(131).AndRaise(
            fakes_nova.fake_exception())
        nova_sgr.SecurityGroupRuleManager.delete(132).AndRaise(
            fakes_nova.fake_exception())
        nova_sgr.SecurityGroupRuleManager.delete(133).AndRaise(
            fakes_nova.fake_exception())
        nova_sg.SecurityGroupManager.delete(2).AndReturn(None)

        nova_sg.SecurityGroupManager.get(2).AndRaise(
            fakes_nova.fake_exception())

        self.m.ReplayAll()
        stack = self.create_stack(self.test_template_nova)

        sg = stack['the_sg']

        self.assertResourceState(sg, utils.PhysName('test_stack', 'the_sg'))

        scheduler.TaskRunner(sg.delete)()

        sg.state_set(sg.CREATE, sg.COMPLETE, 'to delete again')
        sg.resource_id = 2
        stack.delete()

        self.m.VerifyAll()
예제 #49
0
class TestIsNotFound(common.HeatTestCase):

    scenarios = [
        ('ceilometer_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='ceilometer',
            exception=lambda: ceil_exc.HTTPNotFound(details='gone'),
        )),
        ('ceilometer_not_found_apiclient', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='ceilometer',
            exception=lambda: c_a_exc.NotFound(details='gone'),
        )),
        ('ceilometer_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='ceilometer',
            exception=lambda: Exception()
        )),
        ('ceilometer_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='ceilometer',
            exception=lambda: ceil_exc.HTTPOverLimit(details='over'),
        )),
        ('ceilometer_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='ceilometer',
            exception=lambda: ceil_exc.HTTPConflict(),
        )),
        ('cinder_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='cinder',
            exception=lambda: cinder_exc.NotFound(code=404),
        )),
        ('cinder_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='cinder',
            exception=lambda: Exception()
        )),
        ('cinder_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='cinder',
            exception=lambda: cinder_exc.OverLimit(code=413),
        )),
        ('cinder_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='cinder',
            exception=lambda: cinder_exc.ClientException(code=409),
        )),
        ('glance_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='glance',
            exception=lambda: glance_exc.HTTPNotFound(details='gone'),
        )),
        ('glance_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='glance',
            exception=lambda: Exception()
        )),
        ('glance_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='glance',
            exception=lambda: glance_exc.HTTPOverLimit(details='over'),
        )),
        ('glance_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='glance',
            exception=lambda: glance_exc.HTTPConflict(),
        )),
        ('heat_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='heat',
            exception=lambda: heat_exc.HTTPNotFound(message='gone'),
        )),
        ('heat_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='heat',
            exception=lambda: Exception()
        )),
        ('heat_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='heat',
            exception=lambda: heat_exc.HTTPOverLimit(message='over'),
        )),
        ('heat_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='heat',
            exception=lambda: heat_exc.HTTPConflict(),
        )),
        ('keystone_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='keystone',
            exception=lambda: keystone_exc.NotFound(details='gone'),
        )),
        ('keystone_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='keystone',
            exception=lambda: Exception()
        )),
        ('keystone_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='keystone',
            exception=lambda: keystone_exc.RequestEntityTooLarge(
                details='over'),
        )),
        ('keystone_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='keystone',
            exception=lambda: keystone_exc.Conflict(
                message='Conflict'),
        )),
        ('neutron_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='neutron',
            exception=lambda: neutron_exc.NotFound,
        )),
        ('neutron_network_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='neutron',
            exception=lambda: neutron_exc.NetworkNotFoundClient(),
        )),
        ('neutron_port_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='neutron',
            exception=lambda: neutron_exc.PortNotFoundClient(),
        )),
        ('neutron_status_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='neutron',
            exception=lambda: neutron_exc.NeutronClientException(
                status_code=404),
        )),
        ('neutron_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='neutron',
            exception=lambda: Exception()
        )),
        ('neutron_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='neutron',
            exception=lambda: neutron_exc.NeutronClientException(
                status_code=413),
        )),
        ('neutron_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='neutron',
            exception=lambda: neutron_exc.Conflict(),
        )),
        ('nova_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            is_unprocessable_entity=False,
            plugin='nova',
            exception=lambda: fakes_nova.fake_exception(),
        )),
        ('nova_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            is_unprocessable_entity=False,
            plugin='nova',
            exception=lambda: Exception()
        )),
        ('nova_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            is_unprocessable_entity=False,
            plugin='nova',
            exception=lambda: fakes_nova.fake_exception(413),
        )),
        ('nova_unprocessable_entity', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            is_unprocessable_entity=True,
            plugin='nova',
            exception=lambda: fakes_nova.fake_exception(422),
        )),
        ('nova_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            is_unprocessable_entity=False,
            plugin='nova',
            exception=lambda: fakes_nova.fake_exception(409),
        )),
        ('swift_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='swift',
            exception=lambda: swift_exc.ClientException(
                msg='gone', http_status=404),
        )),
        ('swift_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='swift',
            exception=lambda: Exception()
        )),
        ('swift_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='swift',
            exception=lambda: swift_exc.ClientException(
                msg='ouch', http_status=413),
        )),
        ('swift_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='swift',
            exception=lambda: swift_exc.ClientException(
                msg='conflict', http_status=409),
        )),
        ('trove_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='trove',
            exception=lambda: troveclient.exceptions.NotFound(message='gone'),
        )),
        ('trove_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='trove',
            exception=lambda: Exception()
        )),
        ('trove_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='trove',
            exception=lambda: troveclient.exceptions.RequestEntityTooLarge(
                message='over'),
        )),
        ('trove_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='trove',
            exception=lambda: troveclient.exceptions.Conflict(
                message='Conflict'),
        )),
        ('sahara_not_found', dict(
            is_not_found=True,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=False,
            plugin='sahara',
            exception=lambda: sahara_base.APIException(
                error_message='gone1', error_code=404),
        )),
        ('sahara_exception', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=False,
            is_conflict=False,
            plugin='sahara',
            exception=lambda: Exception()
        )),
        ('sahara_overlimit', dict(
            is_not_found=False,
            is_over_limit=True,
            is_client_exception=True,
            is_conflict=False,
            plugin='sahara',
            exception=lambda: sahara_base.APIException(
                error_message='over1', error_code=413),
        )),
        ('sahara_conflict', dict(
            is_not_found=False,
            is_over_limit=False,
            is_client_exception=True,
            is_conflict=True,
            plugin='sahara',
            exception=lambda: sahara_base.APIException(
                error_message='conflict1', error_code=409),
        )),
    ]

    def test_is_not_found(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            if self.is_not_found != client_plugin.is_not_found(e):
                raise

    def test_ignore_not_found(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            exp = self.exception()
            exp_class = exp.__class__
            raise exp
        except Exception as e:
            if self.is_not_found:
                client_plugin.ignore_not_found(e)
            else:
                self.assertRaises(exp_class,
                                  client_plugin.ignore_not_found,
                                  e)

    def test_ignore_conflict_and_not_found(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            exp = self.exception()
            exp_class = exp.__class__
            raise exp
        except Exception as e:
            if self.is_conflict or self.is_not_found:
                client_plugin.ignore_conflict_and_not_found(e)
            else:
                self.assertRaises(exp_class,
                                  client_plugin.ignore_conflict_and_not_found,
                                  e)

    def test_is_over_limit(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            if self.is_over_limit != client_plugin.is_over_limit(e):
                raise

    def test_is_client_exception(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            ice = self.is_client_exception
            actual = client_plugin.is_client_exception(e)
            if ice != actual:
                raise

    def test_is_conflict(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            if self.is_conflict != client_plugin.is_conflict(e):
                raise

    def test_is_unprocessable_entity(self):
        con = mock.Mock()
        c = clients.Clients(con)
        # only 'nova' client plugin need to check this exception
        if self.plugin == 'nova':
            client_plugin = c.client_plugin(self.plugin)
            try:
                raise self.exception()
            except Exception as e:
                iue = self.is_unprocessable_entity
                if iue != client_plugin.is_unprocessable_entity(e):
                    raise
    def test_security_group_nova_exception(self):
        # create script
        self.mock_no_neutron()
        nova.NovaClientPlugin._create().AndReturn(self.fc)
        sg_name = utils.PhysName('test_stack', 'the_sg')
        nova_sg.SecurityGroupManager.list().MultipleTimes().AndReturn([
            NovaSG(
                id=2,
                name=sg_name,
                description='HTTP and SSH access',
                rules=[],
            ),
            NovaSG(
                id=1,
                name='test',
                description='FAKE_SECURITY_GROUP',
                rules=[],
            )
        ])

        nova_sgr.SecurityGroupRuleManager.create(
            2, 'tcp', 22, 22, '0.0.0.0/0', None).AndRaise(
                fakes_nova.fake_exception(400, 'Rule already exists'))
        nova_sgr.SecurityGroupRuleManager.create(
            2, 'tcp', 80, 80, '0.0.0.0/0', None).AndReturn(
                fakes_nova.fake_exception(400, 'Rule already exists'))
        nova_sgr.SecurityGroupRuleManager.create(
            2, 'tcp', None, None, None,
            1).AndReturn(fakes_nova.fake_exception(400, 'Rule already exists'))
        nova_sgr.SecurityGroupRuleManager.create(
            2, 'icmp', None, None, None, '1').AndReturn(
                fakes_nova.fake_exception(400, 'Rule already exists'))

        # delete script
        nova_sg.SecurityGroupManager.get(2).AndReturn(
            NovaSG(id=2,
                   name=sg_name,
                   description='HTTP and SSH access',
                   rules=[{
                       "from_port": 22,
                       "group": {},
                       "ip_protocol": "tcp",
                       "to_port": 22,
                       "parent_group_id": 2,
                       "ip_range": {
                           "cidr": "0.0.0.0/0"
                       },
                       'id': 130
                   }, {
                       'from_port': 80,
                       'group': {},
                       'ip_protocol': 'tcp',
                       'to_port': 80,
                       'parent_group_id': 2,
                       'ip_range': {
                           'cidr': '0.0.0.0/0'
                       },
                       'id': 131
                   }, {
                       'from_port': None,
                       'group': {
                           'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
                           'name': 'test'
                       },
                       'ip_protocol': 'tcp',
                       'to_port': None,
                       'parent_group_id': 2,
                       'ip_range': {},
                       'id': 132
                   }, {
                       'from_port': None,
                       'group': {
                           'tenant_id': 'f18ca530cc05425e8bac0a5ff92f7e88',
                           'name': 'test'
                       },
                       'ip_protocol': 'icmp',
                       'to_port': None,
                       'parent_group_id': 2,
                       'ip_range': {},
                       'id': 133
                   }]))
        nova_sgr.SecurityGroupRuleManager.delete(130).AndRaise(
            fakes_nova.fake_exception())
        nova_sgr.SecurityGroupRuleManager.delete(131).AndRaise(
            fakes_nova.fake_exception())
        nova_sgr.SecurityGroupRuleManager.delete(132).AndRaise(
            fakes_nova.fake_exception())
        nova_sgr.SecurityGroupRuleManager.delete(133).AndRaise(
            fakes_nova.fake_exception())
        nova_sg.SecurityGroupManager.delete(2).AndReturn(None)

        nova_sg.SecurityGroupManager.get(2).AndRaise(
            fakes_nova.fake_exception())

        self.m.ReplayAll()
        stack = self.create_stack(self.test_template_nova)

        sg = stack['the_sg']

        self.assertResourceState(sg, utils.PhysName('test_stack', 'the_sg'))

        scheduler.TaskRunner(sg.delete)()

        sg.state_set(sg.CREATE, sg.COMPLETE, 'to delete again')
        sg.resource_id = 2
        stack.delete()

        self.m.VerifyAll()