def test_unset_subport(self): tenant_id = 'ten-4' network_id = 'net4-id' vm_id = 'vm4' trunk_id = 111 device_owner = 'trunk:subport' host_id = 'host1' port_id = 'p1' vnic_type = 'allowed' profile = [] trunk_port = models_v2.Port(tenant_id=tenant_id, network_id=network_id, device_id=vm_id, device_owner='compute:None') trunk_port.port_binding = port_models.PortBinding() trunk_port.port_binding.vnic_type = vnic_type trunk_port.port_binding.host = host_id trunk_port.port_binding.profile = profile mechanism_arista.db_lib.tenant_provisioned.return_value = False mechanism_arista.db_lib.get_trunk_port_by_trunk_id.return_value = \ trunk_port resource = 'SubPort' event = 'AFTER_DELETE' trigger = 'AristaDriver' subport = trunk_models.SubPort() subport.port_id = port_id payload = callbacks.TrunkPayload(None, trunk_id, subports=[trunk_models.SubPort()]) sp = models_v2.Port(id=port_id, device_owner='trunk:subport', network_id=network_id) self.drv.ndb.get_port.return_value = sp self.drv.unset_subport(resource, event, trigger, payload=payload) expected_calls = [ mock.call.NeutronNets(), mock.call.get_trunk_port_by_trunk_id(trunk_id), mock.call.unplug_port_from_network(vm_id, device_owner, host_id, port_id, network_id, tenant_id, [], vnic_type, switch_bindings=profile, trunk_details=None), mock.call.remove_security_group([], profile), mock.call.tenant_provisioned(tenant_id), mock.call.delete_tenant(tenant_id), ] mechanism_arista.db_lib.assert_has_calls(expected_calls)
def test_trunk_subports_set_status_delete(self, mock_set_subport_status): resource = trunk_consts.SUBPORTS event_type = events.AFTER_DELETE fake_payload = self._fake_trunk_payload() fake_payload.subports = [models.SubPort(port_id='fake_port_id', segmentation_id=101, segmentation_type='vlan', trunk_id='fake_id')] self.handler.trunk_subports_set_status(resource, event_type, mock.ANY, fake_payload) mock_set_subport_status.assert_called_once_with( mock.ANY, mock.ANY, 'fake_port_id', n_const.PORT_STATUS_DOWN)
def test_trunk_subports_set_status_create_parent_active( self, mock_set_subport_status): resource = trunk_consts.SUBPORTS event_type = events.AFTER_CREATE fake_payload = self._fake_trunk_payload() core_plugin = directory.get_plugin() fake_payload.subports = [models.SubPort(port_id='fake_port_id', segmentation_id=101, segmentation_type='vlan', trunk_id='fake_id')] parent_port = FAKE_PARENT with mock.patch.object(core_plugin, '_get_port') as gp: gp.return_value = parent_port self.handler.trunk_subports_set_status(resource, event_type, mock.ANY, fake_payload) mock_set_subport_status.assert_called_once_with( core_plugin, mock.ANY, 'fake_port_id', n_const.PORT_STATUS_ACTIVE)
def test_trunk_port(self): with self.session.begin(subtransactions=True): self.session.add(trunk_model.SubPort( port_id=self.port_id_2, trunk_id=self.trunk_id_1, segmentation_type="vlan", segmentation_id=11 )) self.session.add(ml2_models.PortBinding( port_id=self.port_id_2, host=self.host, vif_type="ovs" )) self.session.add(ml2_models.PortBindingLevel( port_id=self.port_id_2, host=self.host, driver=nsxv3_constants.NSXV3, level=1 )) port_2 = db.get_port(self.ctx, self.host, self.port_id_2) self.assertDictSupersetOf( { "id": self.port_id_2, "parent_id": self.port_id_1, "traffic_tag": 11, "admin_state_up": True, "status": "ACTIVE", "qos_policy_id": "", "security_groups": [], "address_bindings": [], "revision_number": 0, "binding:host_id": "test", "vif_details": "", "binding:vnic_type": "normal", "binding:vif_type": "ovs" }, port_2)
def test_set_subport(self): tenant_id = 'ten-4' network_id = 'net4-id' vm_id = 'vm4' trunk_id = 111 host_id = 'host1' port_id = 'p1' vnic_type = 'allowed' profile = [] sg = ['security-groups'] orig_sg = None trunk_port = models_v2.Port(tenant_id=tenant_id, network_id='net-trunk', device_id=vm_id, device_owner='compute:None') trunk_port.port_binding = port_models.PortBinding() trunk_port.port_binding.vnic_type = vnic_type trunk_port.port_binding.host = host_id trunk_port.port_binding.profile = profile mechanism_arista.db_lib.num_nets_provisioned.return_value = 0 mechanism_arista.db_lib.num_vms_provisioned.return_value = 0 mechanism_arista.db_lib.get_trunk_port_by_trunk_id.return_value = \ trunk_port mechanism_arista.db_lib.is_network_provisioned.return_value = True resource = 'SubPort' event = 'AFTER_CREATE' trigger = 'AristaDriver' sp = dict( models_v2.Port(id=port_id, device_owner='trunk:subport', network_id=network_id, name='subport')) sp['security_groups'] = ['security-groups'] subport = trunk_models.SubPort() subport.port_id = port_id payload = callbacks.TrunkPayload(None, trunk_id, subports=[subport]) segments = [{ 'segmentation_id': 12, 'physical_network': 'default', 'id': 'segment_id', 'network_type': 'vlan' }] bindings = [] self.drv.ndb.get_port.return_value = sp self.drv.ndb.get_network_id_from_port_id.return_value = network_id mechanism_arista.db_lib.get_network_segments_by_port_id.return_value = \ segments self.drv.set_subport(resource, event, trigger, payload=payload) expected_calls = [ mock.call.NeutronNets(), mock.call.get_trunk_port_by_trunk_id(trunk_id), mock.call.get_network_segments_by_port_id('p1'), mock.call.plug_port_into_network(vm_id, host_id, port_id, network_id, tenant_id, 'subport', 'trunk:subport', sg, orig_sg, vnic_type, segments=segments, switch_bindings=bindings), ] mechanism_arista.db_lib.assert_has_calls(expected_calls)