Esempio n. 1
0
    def _validate_properties(self, stack, template, expected):
        resource_defns = template.resource_definitions(stack)
        rsrc = eip.ElasticIpAssociation('validate_eip_ass',
                                        resource_defns['IPAssoc'], stack)

        exc = self.assertRaises(exception.StackValidationFailed, rsrc.validate)
        self.assertIn(expected, six.text_type(exc))
Esempio n. 2
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.mock_create_floatingip()
        self.mock_show_floatingip('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
        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()
Esempio n. 3
0
 def create_association(self, t, stack, resource_name):
     resource_defns = stack.t.resource_definitions(stack)
     rsrc = eip.ElasticIpAssociation(resource_name,
                                     resource_defns[resource_name], stack)
     self.assertIsNone(rsrc.validate())
     scheduler.TaskRunner(rsrc.create)()
     self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
     return rsrc
Esempio n. 4
0
 def create_association(self, t, stack, resource_name):
     resource_defn = stack.defn.resource_definition(resource_name)
     rsrc = eip.ElasticIpAssociation(resource_name, resource_defn, stack)
     self.assertIsNone(rsrc.validate())
     scheduler.TaskRunner(rsrc.create)()
     self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
     stk_defn.update_resource_data(stack.defn, resource_name,
                                   rsrc.node_data())
     return rsrc
Esempio n. 5
0
    def test_validate_without_NetworkInterfaceId_and_InstanceId(self):
        template, stack = self._setup_test_stack(
            stack_name='validate_EIP_InstanceId')

        properties = template.t['Resources']['IPAssoc']['Properties']
        # test without NetworkInterfaceId and InstanceId
        properties.pop('InstanceId')
        properties.pop('EIP')
        allocation_id = '1fafbe59-2332-4f5f-bfa4-517b4d6c1b65'
        properties['AllocationId'] = allocation_id
        resource_defns = template.resource_definitions(stack)
        rsrc = eip.ElasticIpAssociation('validate_eip_ass',
                                        resource_defns['IPAssoc'], stack)
        exc = self.assertRaises(exception.PropertyUnspecifiedError,
                                rsrc.validate)
        self.assertIn(
            'At least one of the following properties '
            'must be specified: InstanceId, NetworkInterfaceId',
            six.text_type(exc))
Esempio n. 6
0
    def test_delete_association_successful_if_create_failed(self):
        server = self.fc.servers.list()[0]
        self.patchobject(self.fc.servers, 'get', return_value=server)
        self.mock_create_floatingip()
        self.mock_show_floatingip()
        self.patchobject(server, 'interface_list',
                         side_effect=[q_exceptions.NotFound('Not FOund')])
        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)
Esempio n. 7
0
    def test_delete_association_successful_if_create_failed(self):
        self._mock_server(mock_interface=True)
        self.mock_create_floatingip()
        self.mock_show_floatingip('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
        self.mock_list_floatingips()
        self.mock_update_floatingip(ex=q_exceptions.NotFound('Not Found'))
        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()