예제 #1
0
    def test_alarm_with_wrong_start_time(self):
        t = template_format.parse(alarm_template_with_time_constraints)
        time_constraints = [{
            "name": "tc1",
            "start": "0 23 * * *",
            "timezone": "Asia/Taipei",
            "duration": 10800,
            "description": "a description"
        }]
        self.stack = self.create_stack(template=json.dumps(t),
                                       time_constraints=time_constraints)
        self.m.ReplayAll()
        self.stack.create()
        rsrc = self.stack['MEMAlarmHigh']

        properties = copy.copy(rsrc.properties.data)
        start_time = '* * * * * 100'
        properties.update({
            'comparison_operator':
            'lt',
            'description':
            'fruity',
            'evaluation_periods':
            '2',
            'period':
            '90',
            'enabled':
            True,
            'repeat_actions':
            True,
            'statistic':
            'max',
            'threshold':
            '39',
            'insufficient_data_actions': [],
            'alarm_actions': [],
            'ok_actions': ['signal_handler'],
            'matching_metadata': {
                'x': 'y'
            },
            'query': [dict(field='c', op='ne', value='z')],
            'time_constraints': [{
                "name": "tc1",
                "start": start_time,
                "timezone": "Asia/Taipei",
                "duration": 10800,
                "description": "a description"
            }]
        })
        snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
                                               properties)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.update, snippet))
        self.assertEqual(
            "StackValidationFailed: resources.MEMAlarmHigh: Property error: "
            "MEMAlarmHigh.Properties.time_constraints[0].start: Error "
            "validating value '%s': Invalid CRON expression: "
            "[%s] is not acceptable, out of range" % (start_time, start_time),
            error.message)

        self.m.VerifyAll()
예제 #2
0
    def test_security_group_nova_update(self):
        #create script
        sg_name = self.stubout_nova_create_security_group()
        # update script
        nova_sg.SecurityGroupManager.list().MultipleTimes().AndReturn([
            NovaSG(id='1',
                   name='test',
                   description='FAKE_SECURITY_GROUP',
                   rules=[]),
            NovaSG(id='2', name=sg_name, description='HTTPS access', rules=[]),
            NovaSG(id='3',
                   name='test2',
                   description='FAKE_SECURITY_GROUP',
                   rules=[]),
        ])

        # remove deleted groups
        self.stubout_nova_get_security_group(sg_name)
        nova_sgr.SecurityGroupRuleManager.delete(131).AndReturn(None)
        nova_sgr.SecurityGroupRuleManager.delete(132).AndReturn(None)

        # create missing groups
        nova_sgr.SecurityGroupRuleManager.create(2, 'tcp', 443, 443,
                                                 '0.0.0.0/0',
                                                 None).AndReturn(None)
        nova_sgr.SecurityGroupRuleManager.create(2, 'tcp', None, None, None,
                                                 '3').AndReturn(None)

        self.m.ReplayAll()

        stack = self.create_stack(self.test_template_nova)
        sg = stack['the_sg']
        self.assertResourceState(sg, utils.PhysName('test_stack', 'the_sg'))

        # make updated template
        props = copy.deepcopy(sg.properties.data)
        props['SecurityGroupIngress'] = [
            {
                'IpProtocol': 'tcp',
                'FromPort': '22',
                'ToPort': '22',
                'CidrIp': '0.0.0.0/0'
            },
            {
                'IpProtocol': 'tcp',
                'FromPort': '443',
                'ToPort': '443',
                'CidrIp': '0.0.0.0/0'
            },
            {
                'IpProtocol': 'tcp',
                'SourceSecurityGroupName': 'test2'
            },
            {
                'IpProtocol': 'icmp',
                'SourceSecurityGroupId': '1'
            },
        ]
        after = rsrc_defn.ResourceDefinition(sg.name, sg.type(), props)

        scheduler.TaskRunner(sg.update, after)()

        self.assertEqual((sg.UPDATE, sg.COMPLETE), sg.state)
        self.m.VerifyAll()
예제 #3
0
    def test_network_gateway_update(self):
        rsrc = self.prepare_create_network_gateway()
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35'
        ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35'
        ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35'
        ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35'
        ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35'
        ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            '6af055d3-26f6-48dd-a597-7611d7e58d35'
        ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')

        neutronclient.Client.update_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_gateway': {
                    'name': u'NetworkGatewayUpdate'
                }
            }
        ).AndReturn(None)

        neutronclient.Client.disconnect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 10,
                'segmentation_type': u'vlan'
            }
        ).AndReturn(None)

        neutronclient.Client.connect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 0,
                'segmentation_type': u'flat'
            }
        ).AndReturn({
            'connection_info': {
                'network_gateway_id': u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'port_id': u'aa800972-f6be-4c65-8453-9ab31834bf80'
            }
        })

        neutronclient.Client.disconnect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 10,
                'segmentation_type': u'vlan'
            }
        ).AndRaise(qe.NeutronClientException(status_code=404))

        neutronclient.Client.connect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 0,
                'segmentation_type': u'flat'
            }
        ).AndReturn({
            'connection_info': {
                'network_gateway_id': u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'port_id': u'aa800972-f6be-4c65-8453-9ab31834bf80'
            }
        })

        neutronclient.Client.disconnect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 10,
                'segmentation_type': u'vlan'
            }
        ).AndReturn(None)

        neutronclient.Client.delete_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37'
        ).AndReturn(None)

        neutronclient.Client.create_network_gateway({
            'network_gateway': {
                'name': u'NetworkGateway',
                'devices': [{'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                             'interface_name': u'breth2'}]
            }
        }
        ).AndReturn({
            'network_gateway': {
                'id': 'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                'name': 'NetworkGateway',
                'default': False,
                'tenant_id': '96ba52dc-c5c5-44c6-9a9d-d3ba1a03f77f',
                'devices': [{
                    'id': 'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': 'breth2'}]
            }
        }
        )

        neutronclient.Client.connect_network_gateway(
            u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_id': 10,
                'segmentation_type': u'vlan'
            }
        ).AndReturn({
            'connection_info': {
                'network_gateway_id': u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
                'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'port_id': u'aa800972-f6be-4c65-8453-9ab31834bf80'
            }
        })

        self.m.ReplayAll()

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

        # update name
        snippet_for_update = rsrc_defn.ResourceDefinition(
            rsrc.name,
            rsrc.type(),
            {
                'name': u'NetworkGatewayUpdate',
                'devices': [{
                    'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': u'breth1'}],
                'connections': [{
                    'network': '6af055d3-26f6-48dd-a597-7611d7e58d35',
                    'segmentation_type': 'vlan',
                    'segmentation_id': 10}]
            })
        prop_diff = {'name': u'NetworkGatewayUpdate'}
        self.assertIsNone(rsrc.handle_update(snippet_for_update,
                                             mox.IgnoreArg(),
                                             prop_diff))

        # update connections
        snippet_for_update = rsrc_defn.ResourceDefinition(
            rsrc.name,
            rsrc.type(),
            {
                'name': u'NetworkGateway',
                'devices': [{
                    'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': u'breth1'}],
                'connections': [{
                    'network': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                    'segmentation_type': u'flat',
                    'segmentation_id': 0}]
            })
        prop_diff = {
            'connections': [{
                'network': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                'segmentation_type': u'flat',
                'segmentation_id': 0}]
        }
        self.assertIsNone(rsrc.handle_update(snippet_for_update,
                                             mox.IgnoreArg(),
                                             prop_diff))

        # update connections once more
        self.assertIsNone(rsrc.handle_update(snippet_for_update,
                                             mox.IgnoreArg(),
                                             prop_diff))

        # update devices
        snippet_for_update = rsrc_defn.ResourceDefinition(
            rsrc.name,
            rsrc.type(),
            {
                'name': u'NetworkGateway',
                'devices': [{
                    'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                    'interface_name': u'breth2'}],
                'connections': [{
                    'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
                    'segmentation_type': u'vlan',
                    'segmentation_id': 10}]
            })
        prop_diff = {
            'devices': [{
                'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
                'interface_name': u'breth2'}]
        }
        self.assertIsNone(rsrc.handle_update(snippet_for_update,
                                             mox.IgnoreArg(),
                                             prop_diff))

        self.m.VerifyAll()
예제 #4
0
 def _get_instance_definition(self):
     rsrc = self.properties[self.RESOURCE]
     return rsrc_defn.ResourceDefinition(None,
                                         rsrc['type'],
                                         properties=rsrc.get('properties'),
                                         metadata=rsrc.get('metadata'))
예제 #5
0
    def test_port_needs_update_network(self):
        net1 = '9cfe6c74-c105-4906-9a1f-81d9064e9bca'
        net2 = '0064eec9-5681-4ba7-a745-6f8e32db9503'
        props = {
            'network_id': net1,
            'name': 'test_port',
            'device_owner': u'network:dhcp',
            'binding:vnic_type': 'normal',
            'device_id': ''
        }
        create_kwargs = props.copy()
        create_kwargs['admin_state_up'] = True

        self.find_mock.side_effect = [net1] * 8 + [net2] * 2 + [net1]
        self.create_mock.return_value = {
            'port': {
                "status": "ACTIVE",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        }
        self.port_show_mock.return_value = {
            'port': {
                "status": "ACTIVE",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766",
                "fixed_ips": {
                    "subnet_id": "d0e971a6-a6b4-4f4c-8c88-b75e9c120b7e",
                    "ip_address": "10.0.0.2"
                }
            }
        }

        # create port with network_id
        tmpl = neutron_port_template.replace(
            'network: net1234',
            'network_id: 9cfe6c74-c105-4906-9a1f-81d9064e9bca')
        t = template_format.parse(tmpl)
        t['resources']['port']['properties'].pop('fixed_ips')
        t['resources']['port']['properties']['name'] = 'test_port'
        stack = utils.parse_stack(t)

        port = stack['port']
        scheduler.TaskRunner(port.create)()
        self.assertEqual((port.CREATE, port.COMPLETE), port.state)
        self.create_mock.assert_called_once_with({'port': create_kwargs})

        # Switch from network_id=ID to network=ID (no replace)
        new_props = props.copy()
        new_props['network'] = new_props.pop('network_id')
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_props)

        scheduler.TaskRunner(port.update, update_snippet)()
        self.assertEqual((port.UPDATE, port.COMPLETE), port.state)
        self.assertEqual(0, self.update_mock.call_count)

        # Switch from network=ID to network=NAME (no replace)
        new_props['network'] = 'net1234'
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_props)

        scheduler.TaskRunner(port.update, update_snippet)()
        self.assertEqual((port.UPDATE, port.COMPLETE), port.state)
        self.assertEqual(0, self.update_mock.call_count)

        # Switch to a different network (replace)
        new_props['network'] = 'net5678'
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_props)
        updater = scheduler.TaskRunner(port.update, update_snippet)
        self.assertRaises(resource.UpdateReplace, updater)
        self.assertEqual(11, self.find_mock.call_count)
예제 #6
0
 def _get_resource_definition(self):
     conf, props = self._get_conf_properties()
     return rsrc_defn.ResourceDefinition(None,
                                         SCALED_RESOURCE_TYPE,
                                         props,
                                         conf.t.metadata())
예제 #7
0
    def test_create_and_update_port(self):
        props = {
            'network_id': u'net1234',
            'name': utils.PhysName('test_stack', 'port'),
            'admin_state_up': True,
            'device_owner': u'network:dhcp'
        }
        new_props = props.copy()
        new_props['name'] = "new_name"
        new_props['security_groups'] = ['8a2f582a-e1cd-480f-b85d-b02631c10656']
        new_props_update = new_props.copy()
        new_props_update.pop('network_id')

        new_props1 = new_props.copy()
        new_props1.pop('security_groups')
        new_props_update1 = new_props_update.copy()
        new_props_update1['security_groups'] = [
            '0389f747-7785-4757-b7bb-2ab07e4b09c3'
        ]

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client), 'network',
            'net1234').MultipleTimes().AndReturn('net1234')
        neutronclient.Client.create_port({
            'port': props
        }).AndReturn({
            'port': {
                "status": "BUILD",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        })
        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn({
                'port': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766",
                    "fixed_ips": {
                        "subnet_id": "d0e971a6-a6b4-4f4c-8c88-b75e9c120b7e",
                        "ip_address": "10.0.0.2"
                    }
                }
            })
        neutronclient.Client.update_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'port': new_props_update
            }).AndReturn(None)

        fake_groups_list = {
            'security_groups': [{
                'tenant_id': 'dc4b074874244f7693dd65583733a758',
                'id': '0389f747-7785-4757-b7bb-2ab07e4b09c3',
                'name': 'default',
                'security_group_rules': [],
                'description': 'no protocol'
            }]
        }
        self.m.StubOutWithMock(neutronclient.Client, 'list_security_groups')
        neutronclient.Client.list_security_groups().AndReturn(fake_groups_list)
        neutronclient.Client.update_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'port': new_props_update1
            }).AndReturn(None)

        self.m.ReplayAll()

        # create port
        t = template_format.parse(neutron_port_template)
        t['resources']['port']['properties'].pop('fixed_ips')
        stack = utils.parse_stack(t)

        port = stack['port']
        scheduler.TaskRunner(port.create)()

        # update port
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_props)
        self.assertIsNone(port.handle_update(update_snippet, {}, {}))
        # update again to test port without security group
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_props1)
        self.assertIsNone(port.handle_update(update_snippet, {}, {}))

        self.m.VerifyAll()
예제 #8
0
    def test_floatip_port(self):
        t = template_format.parse(neutron_floating_no_assoc_template)
        t['resources']['port_floating']['properties']['network'] = "xyz1234"
        t['resources']['port_floating']['properties']['fixed_ips'][0][
            'subnet'] = "sub1234"
        t['resources']['router_interface']['properties']['subnet'] = "sub1234"
        stack = utils.parse_stack(t)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            'xyz1234',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('xyz1234')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub1234',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub1234')

        neutronclient.Client.create_port({
            'port': {
                'network_id':
                u'xyz1234',
                'fixed_ips': [{
                    'subnet_id': u'sub1234',
                    'ip_address': u'10.0.0.10'
                }],
                'name':
                utils.PhysName(stack.name, 'port_floating'),
                'admin_state_up':
                True
            }
        }).AndReturn({
            'port': {
                "status": "BUILD",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        })
        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn({
                'port': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            'abcd1234',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('abcd1234')
        neutronclient.Client.create_floatingip({
            'floatingip': {
                'floating_network_id': u'abcd1234',
                'port_id': u'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
            }
        }).AndReturn({
            'floatingip': {
                "status": "ACTIVE",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        })

        # update with new port_id
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': u'2146dfbf-ba77-4083-8e86-d052f671ece5',
                    'fixed_ip_address': None
                }
            }).AndReturn({
                'floatingip': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })

        # update with None port_id
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': None,
                    'fixed_ip_address': None
                }
            }).AndReturn({
                'floatingip': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })

        neutronclient.Client.delete_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn(None)
        neutronclient.Client.show_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
                qe.NeutronClientException(status_code=404))

        neutronclient.Client.delete_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn(None)

        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
                qe.PortNotFoundClient(status_code=404))
        self.stub_PortConstraint_validate()

        self.m.ReplayAll()

        # check dependencies for fip resource
        required_by = set(
            stack.dependencies.required_by(stack['router_interface']))
        self.assertIn(stack['floating_ip'], required_by)

        p = stack['port_floating']
        scheduler.TaskRunner(p.create)()
        self.assertEqual((p.CREATE, p.COMPLETE), p.state)

        fip = stack['floating_ip']
        scheduler.TaskRunner(fip.create)()
        self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)

        # test update FloatingIp with port_id
        props = copy.deepcopy(fip.properties.data)
        update_port_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
        props['port_id'] = update_port_id
        update_snippet = rsrc_defn.ResourceDefinition(
            fip.name, fip.type(), stack.t.parse(stack, props))
        scheduler.TaskRunner(fip.update, update_snippet)()
        self.assertEqual((fip.UPDATE, fip.COMPLETE), fip.state)

        # test update FloatingIp with None port_id
        props = copy.deepcopy(fip.properties.data)
        del (props['port_id'])
        update_snippet = rsrc_defn.ResourceDefinition(
            fip.name, fip.type(), stack.t.parse(stack, props))
        scheduler.TaskRunner(fip.update, update_snippet)()
        self.assertEqual((fip.UPDATE, fip.COMPLETE), fip.state)

        scheduler.TaskRunner(fip.delete)()
        scheduler.TaskRunner(p.delete)()

        self.m.VerifyAll()
예제 #9
0
    def test_subnet(self):
        update_props = {
            'subnet': {
                'dns_nameservers': ['8.8.8.8', '192.168.1.254'],
                'name':
                'mysubnet',
                'enable_dhcp':
                True,
                'host_routes': [{
                    'destination': '192.168.1.0/24',
                    'nexthop': '194.168.1.2'
                }],
                'gateway_ip':
                '10.0.3.105',
                'tags': ['tag2', 'tag3'],
                'allocation_pools': [{
                    'start': '10.0.3.20',
                    'end': '10.0.3.100'
                }, {
                    'start': '10.0.3.110',
                    'end': '10.0.3.200'
                }]
            }
        }

        t, stack = self._setup_mock(tags=['tag1', 'tag2'])
        create_props = {
            'subnet': {
                'name':
                utils.PhysName(stack.name, 'test_subnet'),
                'network_id':
                'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
                'dns_nameservers': [u'8.8.8.8'],
                'allocation_pools': [{
                    'start': u'10.0.3.20',
                    'end': u'10.0.3.150'
                }],
                'host_routes': [{
                    'destination': u'10.0.4.0/24',
                    'nexthop': u'10.0.3.20'
                }],
                'ip_version':
                4,
                'cidr':
                u'10.0.3.0/24',
                'tenant_id':
                'c1210485b2424d48804aad5d39c61b8f',
                'enable_dhcp':
                True
            }
        }

        self.patchobject(stack['net'],
                         'FnGetRefId',
                         return_value='fc68ea2c-b60b-4b4f-bd82-94ec81110766')
        set_tag_mock = self.patchobject(neutronclient.Client, 'replace_tag')
        rsrc = self.create_subnet(t, stack, 'sub_net')
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        self.create_mock.assert_called_once_with(create_props)
        set_tag_mock.assert_called_once_with('subnets', rsrc.resource_id,
                                             {'tags': ['tag1', 'tag2']})
        rsrc.validate()
        ref_id = rsrc.FnGetRefId()
        self.assertEqual('91e47a57-7508-46fe-afc9-fc454e8580e1', ref_id)
        self.assertIsNone(rsrc.FnGetAtt('network_id'))
        self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766',
                         rsrc.FnGetAtt('network_id'))
        self.assertEqual('8.8.8.8', rsrc.FnGetAtt('dns_nameservers')[0])

        # assert the dependency (implicit or explicit) between the ports
        # and the subnet

        self.assertIn(stack['port'], stack.dependencies[stack['sub_net']])
        self.assertIn(stack['port2'], stack.dependencies[stack['sub_net']])
        update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
                                                      update_props['subnet'])
        rsrc.handle_update(update_snippet, {}, update_props['subnet'])
        self.update_mock.assert_called_once_with(
            '91e47a57-7508-46fe-afc9-fc454e8580e1', update_props)
        set_tag_mock.assert_called_with('subnets', rsrc.resource_id,
                                        {'tags': ['tag2', 'tag3']})
        # with name None
        del update_props['subnet']['name']
        rsrc.handle_update(update_snippet, {}, update_props['subnet'])
        self.update_mock.assert_called_with(
            '91e47a57-7508-46fe-afc9-fc454e8580e1', update_props)

        # with no prop_diff
        rsrc.handle_update(update_snippet, {}, {})

        self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
        rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE, 'to delete again')
        self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
예제 #10
0
 def test_dependencies_explicit_invalid(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType', depends=['baz'])
     stack = {'foo': 'FOO', 'bar': 'BAR'}
     self.assertRaises(exception.InvalidTemplateReference,
                       lambda: list(rd.dependencies(stack)))
예제 #11
0
    def test_floatip_association_port(self):
        t = template_format.parse(neutron_floating_template)
        stack = utils.parse_stack(t)

        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'network',
            'abcd1234',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('abcd1234')
        neutronV20.find_resourceid_by_name_or_id(
            mox.IsA(neutronclient.Client),
            'subnet',
            'sub1234',
            cmd_resource=None,
        ).MultipleTimes().AndReturn('sub1234')
        neutronclient.Client.create_floatingip({
            'floatingip': {
                'floating_network_id': u'abcd1234'
            }
        }).AndReturn({
            'floatingip': {
                "status": "ACTIVE",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        })

        neutronclient.Client.create_port({
            'port': {
                'network_id':
                u'abcd1234',
                'fixed_ips': [{
                    'subnet_id': u'sub1234',
                    'ip_address': u'10.0.0.10'
                }],
                'name':
                utils.PhysName(stack.name, 'port_floating'),
                'admin_state_up':
                True
            }
        }).AndReturn({
            'port': {
                "status": "BUILD",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        })
        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn({
                'port': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        # create as
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': u'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
                }
            }).AndReturn({
                'floatingip': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        # update as with port_id
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': u'2146dfbf-ba77-4083-8e86-d052f671ece5',
                    'fixed_ip_address': None
                }
            }).AndReturn({
                'floatingip': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        # update as with floatingip_id
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': None
                }
            }).AndReturn(None)
        neutronclient.Client.update_floatingip(
            '2146dfbf-ba77-4083-8e86-d052f671ece5', {
                'floatingip': {
                    'port_id': u'2146dfbf-ba77-4083-8e86-d052f671ece5',
                    'fixed_ip_address': None
                }
            }).AndReturn({
                'floatingip': {
                    "status": "ACTIVE",
                    "id": "2146dfbf-ba77-4083-8e86-d052f671ece5"
                }
            })
        # update as with both
        neutronclient.Client.update_floatingip(
            '2146dfbf-ba77-4083-8e86-d052f671ece5', {
                'floatingip': {
                    'port_id': None
                }
            }).AndReturn(None)
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': u'ade6fcac-7d47-416e-a3d7-ad12efe445c1',
                    'fixed_ip_address': None
                }
            }).AndReturn({
                'floatingip': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        # delete as
        neutronclient.Client.update_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'floatingip': {
                    'port_id': None
                }
            }).AndReturn(None)

        neutronclient.Client.delete_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn(None)

        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
                qe.PortNotFoundClient(status_code=404))

        neutronclient.Client.delete_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn(None)
        neutronclient.Client.show_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
                qe.NeutronClientException(status_code=404))

        neutronclient.Client.delete_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
                qe.PortNotFoundClient(status_code=404))

        neutronclient.Client.delete_floatingip(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
                qe.NeutronClientException(status_code=404))
        self.stub_PortConstraint_validate()

        self.m.ReplayAll()

        fip = stack['floating_ip']
        scheduler.TaskRunner(fip.create)()
        self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)

        p = stack['port_floating']
        scheduler.TaskRunner(p.create)()
        self.assertEqual((p.CREATE, p.COMPLETE), p.state)

        fipa = stack['floating_ip_assoc']
        scheduler.TaskRunner(fipa.create)()
        self.assertEqual((fipa.CREATE, fipa.COMPLETE), fipa.state)
        self.assertIsNotNone(fipa.id)
        self.assertEqual(fipa.id, fipa.resource_id)

        fipa.validate()

        # test update FloatingIpAssociation with port_id
        props = copy.deepcopy(fipa.properties.data)
        update_port_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
        props['port_id'] = update_port_id
        update_snippet = rsrc_defn.ResourceDefinition(
            fipa.name, fipa.type(), stack.t.parse(stack, props))

        scheduler.TaskRunner(fipa.update, update_snippet)()
        self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)

        # test update FloatingIpAssociation with floatingip_id
        props = copy.deepcopy(fipa.properties.data)
        update_flip_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
        props['floatingip_id'] = update_flip_id
        update_snippet = rsrc_defn.ResourceDefinition(fipa.name, fipa.type(),
                                                      props)

        scheduler.TaskRunner(fipa.update, update_snippet)()
        self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)

        # test update FloatingIpAssociation with port_id and floatingip_id
        props = copy.deepcopy(fipa.properties.data)
        update_flip_id = 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
        update_port_id = 'ade6fcac-7d47-416e-a3d7-ad12efe445c1'
        props['floatingip_id'] = update_flip_id
        props['port_id'] = update_port_id
        update_snippet = rsrc_defn.ResourceDefinition(fipa.name, fipa.type(),
                                                      props)

        scheduler.TaskRunner(fipa.update, update_snippet)()
        self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)

        scheduler.TaskRunner(fipa.delete)()
        scheduler.TaskRunner(p.delete)()
        scheduler.TaskRunner(fip.delete)()

        fip.state_set(fip.CREATE, fip.COMPLETE, 'to delete again')
        p.state_set(p.CREATE, p.COMPLETE, 'to delete again')

        self.assertIsNone(scheduler.TaskRunner(p.delete)())
        scheduler.TaskRunner(fip.delete)()

        self.m.VerifyAll()
예제 #12
0
 def test_deletion_policy(self):
     rd = rsrc_defn.ResourceDefinition(
         'rsrc',
         'SomeType',
         deletion_policy=rsrc_defn.ResourceDefinition.RETAIN)
     self.assertEqual({'Type': 'SomeType', 'DeletionPolicy': 'Retain'}, rd)
예제 #13
0
 def test_metadata(self):
     rd = rsrc_defn.ResourceDefinition('rsrc',
                                       'SomeType',
                                       metadata={'Foo': 'bar'})
     self.assertEqual({'Type': 'SomeType', 'Metadata': {'Foo': 'bar'}}, rd)
예제 #14
0
 def test_type(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType')
     self.assertEqual({'Type': 'SomeType'}, rd)
예제 #15
0
 def test_dependencies_default(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType')
     stack = {'foo': 'FOO', 'bar': 'BAR'}
     self.assertEqual(set(), rd.required_resource_names())
     self.assertEqual([], list(rd.dependencies(stack)))
예제 #16
0
 def test_deletion_policy_default(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType')
     self.assertEqual(rsrc_defn.ResourceDefinition.DELETE,
                      rd.deletion_policy())
예제 #17
0
 def test_dependencies_explicit(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType', depends=['foo'])
     stack = {'foo': 'FOO', 'bar': 'BAR'}
     self.assertEqual({'foo'}, rd.required_resource_names())
     self.assertEqual(['FOO'], list(rd.dependencies(stack)))
예제 #18
0
 def test_deletion_policy(self):
     for policy in rsrc_defn.ResourceDefinition.DELETION_POLICIES:
         rd = rsrc_defn.ResourceDefinition('rsrc',
                                           'SomeType',
                                           deletion_policy=policy)
         self.assertEqual(policy, rd.deletion_policy())
예제 #19
0
    def test_to_parameters(self):
        """Tests property conversion to parameter values."""
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Foo': {
                    'Type': 'String'
                },
                'AList': {
                    'Type': 'CommaDelimitedList'
                },
                'MemList': {
                    'Type': 'CommaDelimitedList'
                },
                'ListEmpty': {
                    'Type': 'CommaDelimitedList'
                },
                'ANum': {
                    'Type': 'Number'
                },
                'AMap': {
                    'Type': 'Json'
                },
            },
            'Outputs': {
                'Foo': {
                    'Value': 'bar'
                },
            },
        }

        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(generic_rsrc.GenericResource):
            attributes_schema = {"Foo": attributes.Schema("A test attribute")}
            properties_schema = {
                "Foo": {
                    "Type": "String"
                },
                "AList": {
                    "Type": "List"
                },
                "MemList": {
                    "Type": "List"
                },
                "ListEmpty": {
                    "Type": "List"
                },
                "ANum": {
                    "Type": "Number"
                },
                "AMap": {
                    "Type": "Map"
                }
            }

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        map_prop_val = {
            "key1": "val1",
            "key2": ["lval1", "lval2", "lval3"],
            "key3": {
                "key4": 4,
                "key5": False
            }
        }
        prop_vals = {
            "Foo":
            "Bar",
            "AList": ["one", "two", "three"],
            "MemList": [
                collections.OrderedDict([
                    ('key', 'name'),
                    ('value', 'three'),
                ]),
                collections.OrderedDict([
                    ('key', 'name'),
                    ('value', 'four'),
                ])
            ],
            "ListEmpty": [],
            "ANum":
            5,
            "AMap":
            map_prop_val,
        }
        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  'DummyResource', prop_vals)
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        temp_res.validate()
        converted_params = temp_res.child_params()
        self.assertTrue(converted_params)
        for key in DummyResource.properties_schema:
            self.assertIn(key, converted_params)
        # verify String conversion
        self.assertEqual("Bar", converted_params.get("Foo"))
        # verify List conversion
        self.assertEqual("one,two,three", converted_params.get("AList"))
        # verify Member List conversion
        mem_exp = ('.member.0.key=name,'
                   '.member.0.value=three,'
                   '.member.1.key=name,'
                   '.member.1.value=four')
        self.assertEqual(sorted(mem_exp.split(',')),
                         sorted(converted_params.get("MemList").split(',')))
        # verify Number conversion
        self.assertEqual(5, converted_params.get("ANum"))
        # verify Map conversion
        self.assertEqual(map_prop_val, converted_params.get("AMap"))

        with mock.patch.object(properties.Properties,
                               'get_user_value') as m_get:
            m_get.side_effect = ValueError('boom')

            # If the property doesn't exist on INIT, return default value
            temp_res.action = temp_res.INIT
            converted_params = temp_res.child_params()
            for key in DummyResource.properties_schema:
                self.assertIn(key, converted_params)
            self.assertEqual({}, converted_params['AMap'])
            self.assertEqual(0, converted_params['ANum'])

            # If the property doesn't exist past INIT, then error out
            temp_res.action = temp_res.CREATE
            self.assertRaises(ValueError, temp_res.child_params)
예제 #20
0
        def get_param_defn(value):
            stack = FakeStack({'Foo': value})
            param_func = hot_funcs.GetParam(stack, 'get_param', 'Foo')

            return rsrc_defn.ResourceDefinition('rsrc', 'SomeType',
                                                {'Foo': param_func})
예제 #21
0
    def test_vnic_create_update(self):
        port_prop = {
            'network_id': u'net1234',
            'fixed_ips': [{
                'subnet_id': u'sub1234',
                'ip_address': u'10.0.3.21'
            }],
            'name': utils.PhysName('test_stack', 'port'),
            'admin_state_up': True,
            'device_owner': 'network:dhcp',
            'binding:vnic_type': 'direct'
        }
        new_port_prop = port_prop.copy()
        new_port_prop['binding:vnic_type'] = 'normal'
        new_port_prop['name'] = "new_name"
        new_port_prop['security_groups'] = [
            '8a2f582a-e1cd-480f-b85d-b02631c10656'
        ]
        new_port_prop.pop('network_id')

        prop_update = new_port_prop.copy()
        new_port_prop['replacement_policy'] = 'AUTO'
        new_port_prop['network'] = u'net1234'

        neutronV20.find_resourceid_by_name_or_id(mox.IsA(
            neutronclient.Client), 'network', 'net1234').AndReturn('net1234')
        neutronV20.find_resourceid_by_name_or_id(mox.IsA(
            neutronclient.Client), 'subnet', 'sub1234').AndReturn('sub1234')
        neutronclient.Client.create_port({
            'port': port_prop
        }).AndReturn({
            'port': {
                "status": "BUILD",
                "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
            }
        })
        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn({
                'port': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        self.stub_SubnetConstraint_validate()
        self.stub_NetworkConstraint_validate()
        neutronclient.Client.update_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'port': prop_update
            }).AndReturn(None)
        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn({
                'port': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })

        prop_update2 = prop_update.copy()
        prop_update2['binding:vnic_type'] = 'direct'
        neutronclient.Client.update_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766', {
                'port': prop_update2
            }).AndReturn(None)

        neutronclient.Client.show_port(
            'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndReturn({
                'port': {
                    "status": "ACTIVE",
                    "id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
                }
            })
        self.m.ReplayAll()
        t = template_format.parse(neutron_port_template)
        t['resources']['port']['properties']['binding:vnic_type'] = 'direct'
        stack = utils.parse_stack(t)
        port = stack['port']
        scheduler.TaskRunner(port.create)()
        self.assertEqual('direct', port.properties['binding:vnic_type'])

        # update to normal
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_port_prop)
        scheduler.TaskRunner(port.update, update_snippet)()
        self.assertEqual((port.UPDATE, port.COMPLETE), port.state)
        self.assertEqual('normal', port.properties['binding:vnic_type'])

        # update back to direct
        new_port_prop['binding:vnic_type'] = 'direct'
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      new_port_prop)
        scheduler.TaskRunner(port.update, update_snippet)()
        self.assertEqual((port.UPDATE, port.COMPLETE), port.state)
        self.assertEqual('direct', port.properties['binding:vnic_type'])

        self.m.VerifyAll()
예제 #22
0
 def test_hash_names(self):
     rd1 = rsrc_defn.ResourceDefinition('rsrc1', 'SomeType')
     rd2 = rsrc_defn.ResourceDefinition('rsrc2', 'SomeType')
     self.assertEqual(rd1, rd2)
     self.assertEqual(hash(rd1), hash(rd2))
예제 #23
0
    def test_update_port(self):
        t = template_format.parse(neutron_port_template)
        stack = utils.parse_stack(t)

        self.patchobject(neutronV20,
                         'find_resourceid_by_name_or_id',
                         return_value='net1234')
        create_port = self.patchobject(neutronclient.Client, 'create_port')
        update_port = self.patchobject(neutronclient.Client, 'update_port')
        fake_groups_list = {
            'security_groups': [{
                'tenant_id': 'dc4b074874244f7693dd65583733a758',
                'id': '0389f747-7785-4757-b7bb-2ab07e4b09c3',
                'name': 'default',
                'security_group_rules': [],
                'description': 'no protocol'
            }]
        }
        self.patchobject(neutronclient.Client,
                         'list_security_groups',
                         return_value=fake_groups_list)
        set_tag_mock = self.patchobject(neutronclient.Client, 'replace_tag')

        props = {
            'network_id': u'net1234',
            'name': str(utils.PhysName(stack.name, 'port')),
            'admin_state_up': True,
            'device_owner': u'network:dhcp'
        }

        update_props = props.copy()
        update_props['security_groups'] = self.secgrp
        update_props['value_specs'] = self.value_specs
        update_props['tags'] = ['test_tag']
        if self.fixed_ips:
            update_props['fixed_ips'] = self.fixed_ips
        update_props['allowed_address_pairs'] = self.addr_pair
        update_props['binding:vnic_type'] = self.vnic_type

        update_dict = update_props.copy()

        if update_props['security_groups'] is None:
            update_dict['security_groups'] = ['default']

        if update_props['name'] is None:
            update_dict['name'] = utils.PhysName(stack.name, 'test_subnet')

        value_specs = update_dict.pop('value_specs')
        if value_specs:
            for value_spec in six.iteritems(value_specs):
                update_dict[value_spec[0]] = value_spec[1]

        tags = update_dict.pop('tags')

        # create port
        port = stack['port']
        self.assertIsNone(scheduler.TaskRunner(port.handle_create)())
        create_port.assset_called_once_with(props)
        # update port
        update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      update_props)
        self.assertIsNone(
            scheduler.TaskRunner(port.handle_update, update_snippet, {},
                                 update_props)())

        update_port.assset_called_once_with(update_dict)
        set_tag_mock.assert_called_with('ports', port.resource_id,
                                        {'tags': tags})
        # check, that update does not cause of Update Replace
        create_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
                                                      props)
        after_props, before_props = port._prepare_update_props(
            update_snippet, create_snippet)
        self.assertIsNotNone(
            port.update_template_diff_properties(after_props, before_props))

        # With fixed_ips removed
        scheduler.TaskRunner(port.handle_update, update_snippet, {},
                             {'fixed_ips': None})()

        # update with empty prop_diff
        scheduler.TaskRunner(port.handle_update, update_snippet, {}, {})()
        self.assertEqual(1, update_port.call_count)
예제 #24
0
 def test_hash_types(self):
     rd1 = rsrc_defn.ResourceDefinition('rsrc', 'SomeType1')
     rd2 = rsrc_defn.ResourceDefinition('rsrc', 'SomeType2')
     self.assertNotEqual(rd1, rd2)
     self.assertNotEqual(hash(rd1), hash(rd2))
예제 #25
0
    def test_router(self):
        t = template_format.parse(neutron_template)
        stack = utils.parse_stack(t)

        neutronclient.Client.create_router({
            'router': {
                'name': utils.PhysName(stack.name, 'router'),
                'admin_state_up': True,
            }
        }).AndReturn({
            "router": {
                "status": "BUILD",
                "external_gateway_info": None,
                "name": utils.PhysName(stack.name, 'router'),
                "admin_state_up": True,
                "tenant_id": "3e21026f2dc94372b105808c0e721661",
                "id": "3e46229d-8fce-4733-819a-b5fe630550f8",
            }
        })
        neutronclient.Client.list_l3_agent_hosting_routers(
            u'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({"agents": []})
        neutronclient.Client.add_router_to_l3_agent(
            u'792ff887-6c85-4a56-b518-23f24fa65581', {
                'router_id': u'3e46229d-8fce-4733-819a-b5fe630550f8'
            }).AndReturn(None)
        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
                "router": {
                    "status": "BUILD",
                    "external_gateway_info": None,
                    "name": utils.PhysName(stack.name, 'router'),
                    "admin_state_up": True,
                    "tenant_id": "3e21026f2dc94372b105808c0e721661",
                    "routes": [],
                    "id": "3e46229d-8fce-4733-819a-b5fe630550f8"
                }
            })
        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
                "router": {
                    "status": "ACTIVE",
                    "external_gateway_info": None,
                    "name": utils.PhysName(stack.name, 'router'),
                    "admin_state_up": True,
                    "tenant_id": "3e21026f2dc94372b105808c0e721661",
                    "routes": [],
                    "id": "3e46229d-8fce-4733-819a-b5fe630550f8"
                }
            })
        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndRaise(
                qe.NeutronClientException(status_code=404))
        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
                "router": {
                    "status": "ACTIVE",
                    "external_gateway_info": None,
                    "name": utils.PhysName(stack.name, 'router'),
                    "admin_state_up": True,
                    "tenant_id": "3e21026f2dc94372b105808c0e721661",
                    "routes": [],
                    "id": "3e46229d-8fce-4733-819a-b5fe630550f8"
                }
            })
        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
                "router": {
                    "status": "ACTIVE",
                    "external_gateway_info": None,
                    "name": utils.PhysName(stack.name, 'router'),
                    "admin_state_up": True,
                    "tenant_id": "3e21026f2dc94372b105808c0e721661",
                    "routes": [],
                    "id": "3e46229d-8fce-4733-819a-b5fe630550f8"
                }
            })

        # Update script
        neutronclient.Client.list_l3_agent_hosting_routers(
            u'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
                "agents": [{
                    "admin_state_up": True,
                    "agent_type": "L3 agent",
                    "alive": True,
                    "binary": "neutron-l3-agent",
                    "configurations": {
                        "ex_gw_ports": 1,
                        "floating_ips": 0,
                        "gateway_external_network_id": "",
                        "handle_internal_only_routers": True,
                        "interface_driver": "DummyDriver",
                        "interfaces": 1,
                        "router_id": "",
                        "routers": 1,
                        "use_namespaces": True
                    },
                    "created_at": "2014-03-11 05:00:05",
                    "description": None,
                    "heartbeat_timestamp": "2014-03-11 05:01:49",
                    "host": "l3_agent_host",
                    "id": "792ff887-6c85-4a56-b518-23f24fa65581",
                    "started_at": "2014-03-11 05:00:05",
                    "topic": "l3_agent"
                }]
            })
        neutronclient.Client.remove_router_from_l3_agent(
            u'792ff887-6c85-4a56-b518-23f24fa65581',
            u'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn(None)
        neutronclient.Client.add_router_to_l3_agent(
            u'63b3fd83-2c5f-4dad-b3ae-e0f83a40f216', {
                'router_id': u'3e46229d-8fce-4733-819a-b5fe630550f8'
            }).AndReturn(None)
        neutronclient.Client.update_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8',
            {'router': {
                'name': 'myrouter',
                'admin_state_up': False
            }})
        # Update again script
        neutronclient.Client.list_l3_agent_hosting_routers(
            u'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
                "agents": [{
                    "admin_state_up": True,
                    "agent_type": "L3 agent",
                    "alive": True,
                    "binary": "neutron-l3-agent",
                    "configurations": {
                        "ex_gw_ports": 1,
                        "floating_ips": 0,
                        "gateway_external_network_id": "",
                        "handle_internal_only_routers": True,
                        "interface_driver": "DummyDriver",
                        "interfaces": 1,
                        "router_id": "",
                        "routers": 1,
                        "use_namespaces": True
                    },
                    "created_at": "2014-03-11 05:00:05",
                    "description": None,
                    "heartbeat_timestamp": "2014-03-11 05:01:49",
                    "host": "l3_agent_host",
                    "id": "63b3fd83-2c5f-4dad-b3ae-e0f83a40f216",
                    "started_at": "2014-03-11 05:00:05",
                    "topic": "l3_agent"
                }]
            })
        neutronclient.Client.remove_router_from_l3_agent(
            u'63b3fd83-2c5f-4dad-b3ae-e0f83a40f216',
            u'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn(None)
        neutronclient.Client.add_router_to_l3_agent(
            u'4c692423-2c5f-4dad-b3ae-e2339f58539f', {
                'router_id': u'3e46229d-8fce-4733-819a-b5fe630550f8'
            }).AndReturn(None)
        neutronclient.Client.add_router_to_l3_agent(
            u'8363b3fd-2c5f-4dad-b3ae-0f216e0f83a4', {
                'router_id': u'3e46229d-8fce-4733-819a-b5fe630550f8'
            }).AndReturn(None)
        # Delete script
        neutronclient.Client.delete_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn(None)

        neutronclient.Client.show_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndRaise(
                qe.NeutronClientException(status_code=404))

        neutronclient.Client.delete_router(
            '3e46229d-8fce-4733-819a-b5fe630550f8').AndRaise(
                qe.NeutronClientException(status_code=404))

        self.m.ReplayAll()
        rsrc = self.create_router(t, stack, 'router')

        rsrc.validate()

        ref_id = rsrc.FnGetRefId()
        self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8', ref_id)
        self.assertIsNone(rsrc.FnGetAtt('tenant_id'))
        self.assertEqual('3e21026f2dc94372b105808c0e721661',
                         rsrc.FnGetAtt('tenant_id'))

        prop_diff = {
            "admin_state_up": False,
            "name": "myrouter",
            "l3_agent_ids": ["63b3fd83-2c5f-4dad-b3ae-e0f83a40f216"]
        }
        props = copy.copy(rsrc.properties.data)
        props.update(prop_diff)
        update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
                                                      props)
        rsrc.handle_update(update_snippet, {}, prop_diff)

        prop_diff = {
            "l3_agent_ids": [
                "4c692423-2c5f-4dad-b3ae-e2339f58539f",
                "8363b3fd-2c5f-4dad-b3ae-0f216e0f83a4"
            ]
        }
        props = copy.copy(rsrc.properties.data)
        props.update(prop_diff)
        update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
                                                      props)
        rsrc.handle_update(update_snippet, {}, prop_diff)

        self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
        rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE, 'to delete again')
        self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
        self.m.VerifyAll()
예제 #26
0
 def test_properties_default(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType')
     self.assertEqual({}, rd.properties({}))
예제 #27
0
    def test_security_group_neutron_update(self):
        #create script
        self.stubout_neutron_create_security_group()

        # update script
        # delete old not needed rules
        self.stubout_neutron_get_security_group()
        neutronclient.Client.delete_security_group_rule(
            'bbbb').InAnyOrder().AndReturn(None)
        neutronclient.Client.delete_security_group_rule(
            'dddd').InAnyOrder().AndReturn(None)
        neutronclient.Client.delete_security_group_rule(
            'eeee').InAnyOrder().AndReturn(None)

        # create missing rules
        neutronclient.Client.create_security_group_rule({
            'security_group_rule': {
                'direction': 'ingress',
                'remote_group_id': None,
                'remote_ip_prefix': '0.0.0.0/0',
                'port_range_min': 443,
                'ethertype': 'IPv4',
                'port_range_max': 443,
                'protocol': 'tcp',
                'security_group_id': 'aaaa'
            }
        }).InAnyOrder().AndReturn({
            'security_group_rule': {
                'direction': 'ingress',
                'remote_group_id': None,
                'remote_ip_prefix': '0.0.0.0/0',
                'port_range_min': 443,
                'ethertype': 'IPv4',
                'port_range_max': 443,
                'protocol': 'tcp',
                'security_group_id': 'aaaa',
                'id': 'bbbb'
            }
        })
        neutronclient.Client.create_security_group_rule({
            'security_group_rule': {
                'direction': 'ingress',
                'remote_group_id': 'zzzz',
                'remote_ip_prefix': None,
                'port_range_min': None,
                'ethertype': 'IPv4',
                'port_range_max': None,
                'protocol': 'tcp',
                'security_group_id': 'aaaa'
            }
        }).InAnyOrder().AndReturn({
            'security_group_rule': {
                'direction': 'ingress',
                'remote_group_id': 'zzzz',
                'remote_ip_prefix': None,
                'port_range_min': None,
                'ethertype': 'IPv4',
                'port_range_max': None,
                'protocol': 'tcp',
                'security_group_id': 'aaaa',
                'id': 'dddd'
            }
        })

        neutronclient.Client.create_security_group_rule({
            'security_group_rule': {
                'direction': 'egress',
                'remote_group_id': None,
                'remote_ip_prefix': '0.0.0.0/0',
                'port_range_min': 22,
                'ethertype': 'IPv4',
                'port_range_max': 22,
                'protocol': 'tcp',
                'security_group_id': 'aaaa'
            }
        }).InAnyOrder().AndReturn({
            'security_group_rule': {
                'direction': 'egress',
                'remote_group_id': None,
                'remote_ip_prefix': '0.0.0.0/0',
                'port_range_min': 22,
                'ethertype': 'IPv4',
                'port_range_max': 22,
                'protocol': 'tcp',
                'security_group_id': 'aaaa',
                'id': 'eeee'
            }
        })

        self.m.ReplayAll()

        stack = self.create_stack(self.test_template_neutron)
        sg = stack['the_sg']
        self.assertResourceState(sg, 'aaaa')

        # make updated template
        props = copy.deepcopy(sg.properties.data)
        props['SecurityGroupIngress'] = [
            {
                'IpProtocol': 'tcp',
                'FromPort': '80',
                'ToPort': '80',
                'CidrIp': '0.0.0.0/0'
            },
            {
                'IpProtocol': 'tcp',
                'FromPort': '443',
                'ToPort': '443',
                'CidrIp': '0.0.0.0/0'
            },
            {
                'IpProtocol': 'tcp',
                'SourceSecurityGroupId': 'zzzz'
            },
        ]
        props['SecurityGroupEgress'] = [
            {
                'IpProtocol': 'tcp',
                'FromPort': '22',
                'ToPort': '22',
                'CidrIp': '0.0.0.0/0'
            },
            {
                'SourceSecurityGroupName': 'xxxx'
            },
        ]
        after = rsrc_defn.ResourceDefinition(sg.name, sg.type(), props)
        scheduler.TaskRunner(sg.update, after)()

        self.assertEqual((sg.UPDATE, sg.COMPLETE), sg.state)

        self.m.VerifyAll()
예제 #28
0
 def test_metadata_default(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType')
     self.assertEqual({}, rd.metadata())
예제 #29
0
 def test_update_policy_default(self):
     rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType')
     self.assertEqual({}, rd.update_policy({}))
예제 #30
0
    def test_mem_alarm_high_update_no_replace(self):
        """Tests update updatable properties without replacing the Alarm."""

        # short circuit the alarm's references
        t = template_format.parse(alarm_template)
        properties = t['Resources']['MEMAlarmHigh']['Properties']
        properties['alarm_actions'] = ['signal_handler']
        properties['matching_metadata'] = {'a': 'v'}
        properties['query'] = [dict(field='b', op='eq', value='w')]

        self.stack = self.create_stack(template=json.dumps(t))
        self.m.StubOutWithMock(self.fa.alarms, 'update')
        schema = props.schemata(alarm.CeilometerAlarm.properties_schema)
        exns = [
            'period', 'evaluation_periods', 'threshold', 'statistic',
            'comparison_operator', 'meter_name', 'matching_metadata', 'query'
        ]
        al2 = dict((k, mox.IgnoreArg()) for k, s in schema.items()
                   if s.update_allowed and k not in exns)
        al2['time_constraints'] = mox.IgnoreArg()
        al2['alarm_id'] = mox.IgnoreArg()
        al2['type'] = 'threshold'
        al2['threshold_rule'] = dict(meter_name=properties['meter_name'],
                                     period=90,
                                     evaluation_periods=2,
                                     threshold=39,
                                     statistic='max',
                                     comparison_operator='lt',
                                     query=[
                                         dict(field='c', op='ne', value='z'),
                                         dict(field='metadata.metering.x',
                                              op='eq',
                                              value='y')
                                     ])
        self.fa.alarms.update(**al2).AndReturn(None)

        self.m.ReplayAll()
        self.stack.create()
        rsrc = self.stack['MEMAlarmHigh']

        properties = copy.copy(rsrc.properties.data)
        properties.update({
            'comparison_operator': 'lt',
            'description': 'fruity',
            'evaluation_periods': '2',
            'period': '90',
            'enabled': True,
            'repeat_actions': True,
            'statistic': 'max',
            'threshold': '39',
            'insufficient_data_actions': [],
            'alarm_actions': [],
            'ok_actions': ['signal_handler'],
            'matching_metadata': {
                'x': 'y'
            },
            'query': [dict(field='c', op='ne', value='z')]
        })
        snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
                                               properties)

        scheduler.TaskRunner(rsrc.update, snippet)()

        self.m.VerifyAll()