def setUp(self):
        super(TestDetach, self).setUp()
        self.cmd = node_network.Detach(self.app, None)

        self.node = utils.create_mock_object({
            "uuid": "node_uuid_1",
            "name": "node1",
            "provision_state": "active"
        })
        self.neutron_port = utils.create_mock_object({
            "id":
            "neutron_port_uuid_1",
            "network_id":
            "network_uuid",
            "name":
            "node1",
            "mac_address":
            "bb:bb:bb:bb:bb:bb",
            "fixed_ips": [{
                "ip_address": "2.2.2.2"
            }],
            "trunk_details":
            None
        })

        self.app.client_manager.baremetal.node.get.\
            return_value = self.node
    def setUp(self):
        super(TestGetFullNetworkInfoFromPort, self).setUp()
        self.network1 = test_utils.create_mock_object({
            "id":
            "network_uuid_1",
            "name":
            "test_network",
            "provider_segmentation_id":
            "777"
        })
        self.network2 = test_utils.create_mock_object({
            "id":
            "network_uuid_2",
            "name":
            "test_network_2",
            "provider_segmentation_id":
            "888"
        })
        self.subport1 = test_utils.create_mock_object({
            "id":
            "subport_uuid_1",
            "name":
            "test_subport_1",
            "network_id":
            "network_uuid_1",
            "fixed_ips": [{
                "ip_address": '11.22.33.44'
            }]
        })
        self.subport2 = test_utils.create_mock_object({
            "id":
            "subport_uuid_2",
            "name":
            "test_subport_2",
            "network_id":
            "network_uuid_2",
            "fixed_ips": [{
                "ip_address": '55.66.77.88'
            }]
        })

        self.neutron_client = mock.Mock()

        def mock_network_get(network_uuid):
            if network_uuid == "network_uuid_1":
                return self.network1
            elif network_uuid == "network_uuid_2":
                return self.network2
            return None

        self.neutron_client.get_network.side_effect = mock_network_get

        def mock_port_get(port_uuid):
            if port_uuid == "subport_uuid_1":
                return self.subport1
            elif port_uuid == "subport_uuid_2":
                return self.subport2
            return None

        self.neutron_client.get_port.side_effect = mock_port_get
    def test_get_full_network_info_from_port(self):
        port = test_utils.create_mock_object({
            "id":
            "port_uuid",
            "name":
            "test_port",
            "network_id":
            "network_uuid_1",
            "fixed_ips": [{
                "ip_address": '77.77.77.77'
            }],
            "trunk_details": {
                "trunk_id":
                "trunk_uuid",
                "sub_ports": [
                    {
                        "segmentation_id": "777",
                        "port_id": "subport_uuid_1"
                    },
                    {
                        "segmentation_id": "888",
                        "port_id": "subport_uuid_2"
                    },
                ]
            }
        })

        results = utils.get_full_network_info_from_port(
            port, self.neutron_client)
        self.assertEqual(([
            'test_network (777)', 'test_network (777)', 'test_network_2 (888)'
        ], ['test_port', 'test_subport_1', 'test_subport_2'
            ], ['77.77.77.77', '11.22.33.44', '55.66.77.88']), results)
    def setUp(self):
        super(TestDelete, self).setUp()
        self.cmd = trunk.Delete(self.app, None)

        self.trunk = utils.create_mock_object({
            "id":
            "trunk_uuid",
            "name":
            "trunk",
            "port_id":
            "port_uuid_1",
            "sub_ports": [{
                "port_id": 'port_uuid_2',
                "segmentation_id": '222',
                "segmentation_type": 'vlan'
            }, {
                "port_id": 'port_uuid_3',
                "segmentation_id": '333',
                "segmentation_type": 'vlan'
            }]
        })

        def mock_find_trunk(trunk_name):
            if trunk_name == "trunk":
                return self.trunk
            return None
        self.app.client_manager.network.find_trunk.\
            side_effect = mock_find_trunk

        self.app.client_manager.network.delete_trunk.\
            return_value = None
        self.app.client_manager.network.delete_port.\
            return_value = None
    def test_get_network_display_name_no_segmentation_id(self):
        network = test_utils.create_mock_object({
            "id": "network_uuid",
            "name": "test_network"
        })

        results = utils.get_network_display_name(network)
        self.assertEqual('test_network', results)
    def test_get_network_info_from_port_no_fixed_ips(self):
        port = test_utils.create_mock_object({
            "id": "port_uuid",
            "name": "test_port",
            "network_id": "network_uuid",
            "fixed_ips": None
        })

        results = utils.get_network_info_from_port(port, self.neutron_client)
        self.assertEqual(('test_network (777)', ''), results)
    def setUp(self):
        super(TestGetNetworkInfoFromPort, self).setUp()
        self.network = test_utils.create_mock_object({
            "id":
            "network_uuid",
            "name":
            "test_network",
            "provider_segmentation_id":
            "777"
        })

        self.neutron_client = mock.Mock()
        self.neutron_client.get_network.return_value = self.network
    def test_get_network_info_from_port(self):
        port = test_utils.create_mock_object({
            "id":
            "port_uuid",
            "name":
            "test_port",
            "network_id":
            "network_uuid",
            "fixed_ips": [{
                "ip_address": '11.22.33.44'
            }]
        })

        results = utils.get_network_info_from_port(port, self.neutron_client)
        self.assertEqual(('test_network (777)', '11.22.33.44'), results)
    def test_get_full_network_info_from_port_no_trunk(self):
        port = test_utils.create_mock_object({
            "id":
            "port_uuid",
            "name":
            "test_port",
            "network_id":
            "network_uuid_1",
            "fixed_ips": [{
                "ip_address": '77.77.77.77'
            }],
            "trunk_details":
            None
        })

        results = utils.get_full_network_info_from_port(
            port, self.neutron_client)
        self.assertEqual(
            (['test_network (777)'], ['test_port'], ['77.77.77.77']), results)
    def setUp(self):
        super(TestList, self).setUp()
        self.cmd = node_network.List(self.app, None)

        self.port1 = utils.create_mock_object({
            "uuid": "port_uuid_1",
            "node_uuid": "node_uuid_1",
            "address": "aa:aa:aa:aa:aa:aa",
            "internal_info": {
                'tenant_vif_port_id': 'neutron_port_uuid_1'
            }
        })
        self.port2 = utils.create_mock_object({
            "uuid": "port_uuid_2",
            "node_uuid": "node_uuid_2",
            "address": "bb:bb:bb:bb:bb:bb",
            "internal_info": {}
        })
        self.port3 = utils.create_mock_object({
            "uuid": "port_uuid_3",
            "node_uuid": "node_uuid_2",
            "address": "cc:cc:cc:cc:cc:cc",
            "internal_info": {
                'tenant_vif_port_id': 'neutron_port_uuid_2'
            }
        })
        self.node1 = utils.create_mock_object({
            "uuid": "node_uuid_1",
            "name": "node1"
        })
        self.node2 = utils.create_mock_object({
            "uuid": "node_uuid_2",
            "name": "node2"
        })
        self.network = utils.create_mock_object({
            "id": "network_uuid",
            "name": "test_network"
        })
        self.neutron_port1 = utils.create_mock_object({
            "id":
            "neutron_port_uuid_1",
            "network_id":
            "network_uuid",
            "name":
            "node1",
            "fixed_ips": [{
                "ip_address": "1.1.1.1"
            }],
            "trunk_details":
            None
        })
        self.neutron_port2 = utils.create_mock_object({
            "id":
            "neutron_port_uuid_2",
            "network_id":
            "network_uuid",
            "name":
            "node2",
            "fixed_ips": [{
                "ip_address": "2.2.2.2"
            }],
            "trunk_details":
            None
        })

        def mock_node_get(node_uuid):
            if node_uuid == "node_uuid_1":
                return self.node1
            elif node_uuid == "node_uuid_2":
                return self.node2
            return None

        self.app.client_manager.baremetal.node.get.side_effect = mock_node_get

        def mock_neutron_port_get(port_uuid):
            if port_uuid == "neutron_port_uuid_1":
                return self.neutron_port1
            elif port_uuid == "neutron_port_uuid_2":
                return self.neutron_port2
            return None

        self.app.client_manager.network.get_port.\
            side_effect = mock_neutron_port_get
        self.app.client_manager.network.find_network.\
            return_value = self.network
        self.app.client_manager.network.get_network.\
            return_value = self.network
    def setUp(self):
        super(TestAttach, self).setUp()
        self.cmd = node_network.Attach(self.app, None)

        self.port1 = utils.create_mock_object({
            "uuid": "port_uuid_1",
            "node_uuid": "node_uuid_1",
            "address": "aa:aa:aa:aa:aa:aa",
            "internal_info": {
                'tenant_vif_port_id': 'neutron_port_uuid_1'
            }
        })
        self.port2 = utils.create_mock_object({
            "uuid": "port_uuid_2",
            "node_uuid": "node_uuid_1",
            "address": "bb:bb:bb:bb:bb:bb",
            "internal_info": {}
        })
        self.node = utils.create_mock_object({
            "uuid": "node_uuid_1",
            "name": "node1",
            "provision_state": "active"
        })
        self.node_available = utils.create_mock_object({
            "uuid":
            "node_uuid_1",
            "name":
            "node1",
            "provision_state":
            "available"
        })
        self.node_manageable = utils.create_mock_object({
            "uuid": "node_uuid_1",
            "name": "node1",
            "provision_state": "manageable",
            "instance_info": {},
            "driver_info": {
                'deploy_ramdisk': 'fake-image'
            },
        })
        self.node_manageable_instance_info = utils.create_mock_object({
            "uuid":
            "node_uuid_1",
            "name":
            "node1",
            "provision_state":
            "manageable",
            "instance_info": {
                'image_source': 'fake-image',
                'capabilities': {}
            },
            "driver_info": {
                'deploy_ramdisk': 'fake-image'
            },
        })
        self.network = utils.create_mock_object({
            "id": "network_uuid",
            "name": "test_network"
        })
        self.neutron_port = utils.create_mock_object({
            "id":
            "neutron_port_uuid_2",
            "network_id":
            "network_uuid",
            "name":
            "node1-port",
            "mac_address":
            "bb:bb:bb:bb:bb:bb",
            "fixed_ips": [{
                "ip_address": "2.2.2.2"
            }],
            "trunk_details":
            None
        })

        self.app.client_manager.network.find_network.\
            return_value = self.network
        self.app.client_manager.network.get_network.\
            return_value = self.network
        self.app.client_manager.network.create_port.\
            return_value = self.neutron_port
        self.app.client_manager.network.find_port.\
            return_value = self.neutron_port
        self.app.client_manager.network.get_port.\
            return_value = self.neutron_port
Beispiel #12
0
    def setUp(self):
        super(TestRemoveNetwork, self).setUp()
        self.cmd = trunk.RemoveNetwork(self.app, None)

        self.network2 = utils.create_mock_object({
            "id":
            "network_uuid_2",
            "name":
            "network2",
            "provider_segmentation_id":
            222
        })
        self.network3 = utils.create_mock_object({
            "id":
            "network_uuid_3",
            "name":
            "network3",
            "provider_segmentation_id":
            333
        })
        self.subport2 = utils.create_mock_object({
            "id":
            "port_uuid_2",
            "network_id":
            "network_uuid_2",
            "name":
            "trunk-network2-sub-port",
            "mac_address":
            "bb:bb:bb:bb:bb:bb",
        })
        self.subport3 = utils.create_mock_object({
            "id":
            "port_uuid_3",
            "network_id":
            "network_uuid_3",
            "name":
            "trunk-network3-sub-port",
            "mac_address":
            "cc:cc:cc:cc:cc:cc",
        })
        self.trunk = utils.create_mock_object({
            "id":
            "trunk_uuid",
            "name":
            "trunk",
            "port_id":
            "port_uuid_1",
            "sub_ports": [{
                "port_id": 'port_uuid_2',
                "segmentation_id": '222',
                "segmentation_type": 'vlan'
            }, {
                "port_id": 'port_uuid_3',
                "segmentation_id": '333',
                "segmentation_type": 'vlan'
            }]
        })

        def mock_find_trunk(trunk_name):
            if trunk_name == "trunk":
                return self.trunk
            return None
        self.app.client_manager.network.find_trunk.\
            side_effect = mock_find_trunk

        self.app.client_manager.network.delete_trunk_subports.\
            return_value = self.trunk

        self.app.client_manager.network.delete_port.\
            return_value = None
Beispiel #13
0
    def setUp(self):
        super(TestList, self).setUp()
        self.cmd = trunk.List(self.app, None)

        self.port1 = utils.create_mock_object({
            "id":
            "port_uuid_1",
            "network_id":
            "network_uuid_1",
            "name":
            "trunk1-network1-trunk-port",
            "mac_address":
            "aa:aa:aa:aa:aa:aa",
        })
        self.subport2 = utils.create_mock_object({
            "id":
            "port_uuid_2",
            "network_id":
            "network_uuid_2",
            "name":
            "trunk1-network2-sub-port",
            "mac_address":
            "bb:bb:bb:bb:bb:bb",
        })
        self.subport3 = utils.create_mock_object({
            "id":
            "port_uuid_3",
            "network_id":
            "network_uuid_3",
            "name":
            "trunk1-network3-sub-port",
            "mac_address":
            "cc:cc:cc:cc:cc:cc",
        })
        self.port2 = utils.create_mock_object({
            "id":
            "port_uuid_4",
            "network_id":
            "network_uuid_4",
            "name":
            "trunk2-network4-trunk-port",
            "mac_address":
            "dd:dd:dd:dd:dd:dd",
        })
        self.subport3 = utils.create_mock_object({
            "id":
            "port_uuid_5",
            "network_id":
            "network_uuid_5",
            "name":
            "trunk2-network5-sub-port",
            "mac_address":
            "ee:ee:ee:ee:ee",
        })
        self.trunk1 = utils.create_mock_object({
            "id":
            "trunk_uuid_1",
            "name":
            "trunk1",
            "port_id":
            "port_uuid_1",
            "sub_ports": [{
                "port_id": 'port_uuid_2',
                "segmentation_id": '222',
                "segmentation_type": 'vlan'
            }, {
                "port_id": 'port_uuid_3',
                "segmentation_id": '333',
                "segmentation_type": 'vlan'
            }]
        })
        self.trunk2 = utils.create_mock_object({
            "id":
            "trunk_uuid_2",
            "name":
            "trunk2",
            "port_id":
            "port_uuid_4",
            "sub_ports": [{
                "port_id": 'port_uuid_5',
                "segmentation_id": '555',
                "segmentation_type": 'vlan'
            }]
        })

        self.app.client_manager.network.trunks.\
            return_value = [self.trunk1, self.trunk2]

        def mock_get_port(port_id):
            if port_id == "port_uuid_1":
                return self.port1
            if port_id == "port_uuid_4":
                return self.port2
            return None
        self.app.client_manager.network.get_port.\
            side_effect = mock_get_port
Beispiel #14
0
    def setUp(self):
        super(TestCreate, self).setUp()
        self.cmd = trunk.Create(self.app, None)

        self.network1 = utils.create_mock_object({
            "id":
            "network_uuid_1",
            "name":
            "network1",
            "provider_segmentation_id":
            111
        })
        self.network2 = utils.create_mock_object({
            "id":
            "network_uuid_2",
            "name":
            "network2",
            "provider_segmentation_id":
            222
        })
        self.network3 = utils.create_mock_object({
            "id":
            "network_uuid_3",
            "name":
            "network3",
            "provider_segmentation_id":
            333
        })
        self.port = utils.create_mock_object({
            "id":
            "port_uuid_1",
            "network_id":
            "network_uuid_1",
            "name":
            "trunk-network1-trunk-port",
            "mac_address":
            "aa:aa:aa:aa:aa:aa",
        })
        self.subport2 = utils.create_mock_object({
            "id":
            "port_uuid_2",
            "network_id":
            "network_uuid_2",
            "name":
            "trunk-network2-sub-port",
            "mac_address":
            "bb:bb:bb:bb:bb:bb",
        })
        self.subport3 = utils.create_mock_object({
            "id":
            "port_uuid_3",
            "network_id":
            "network_uuid_3",
            "name":
            "trunk-network3-sub-port",
            "mac_address":
            "cc:cc:cc:cc:cc:cc",
        })
        self.trunk = utils.create_mock_object({
            "id":
            "trunk_uuid",
            "name":
            "trunk",
            "port_id":
            "port_uuid_1",
            "sub_ports": [{
                "port_id": 'port_uuid_2',
                "segmentation_id": '222',
                "segmentation_type": 'vlan'
            }, {
                "port_id": 'port_uuid_3',
                "segmentation_id": '333',
                "segmentation_type": 'vlan'
            }]
        })

        def mock_find_network(network_name):
            if network_name == "network1":
                return self.network1
            if network_name == "network2":
                return self.network2
            if network_name == "network3":
                return self.network3
            return None
        self.app.client_manager.network.find_network.\
            side_effect = mock_find_network

        def mock_create_port(name, network_id):
            if network_id == "network_uuid_1":
                return self.port
            if network_id == "network_uuid_2":
                return self.subport2
            if network_id == "network_uuid_3":
                return self.subport3
            return None
        self.app.client_manager.network.create_port.\
            side_effect = mock_create_port

        self.app.client_manager.network.create_trunk.\
            return_value = self.trunk