Exemplo n.º 1
0
    def test_update_router(self):
        scenario = utils.NeutronScenario(context=self.context)
        scenario._generate_random_name = mock.Mock()

        expected_router = {
            "router": {
                "name": scenario._generate_random_name.return_value,
                "admin_state_up": False,
                "fakearg": "fake"
            }
        }
        self.clients("neutron").update_router.return_value = expected_router

        router = {
            "router": {
                "id": "router-id",
                "name": "router-name",
                "admin_state_up": True
            }
        }
        router_update_args = {
            "name": "foo",
            "admin_state_up": False,
            "fakearg": "fake"
        }

        result_router = scenario._update_router(router, router_update_args)
        self.clients("neutron").update_router.assert_called_once_with(
            router["router"]["id"], expected_router)
        self.assertEqual(result_router, expected_router)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_router")
Exemplo n.º 2
0
    def test_create_subnet(self, mock__generate_random_name):
        scenario = utils.NeutronScenario(self.context)
        network_id = "fake-id"
        start_cidr = "192.168.0.0/24"

        network = {"network": {"id": network_id}}
        expected_subnet_data = {
            "subnet": {
                "network_id": network_id,
                "cidr": start_cidr,
                "ip_version": scenario.SUBNET_IP_VERSION,
                "name": mock__generate_random_name.return_value
            }
        }

        # Default options
        subnet_data = {"network_id": network_id}
        scenario._create_subnet(network, subnet_data, start_cidr)
        self.clients("neutron").create_subnet.assert_called_once_with(
            expected_subnet_data)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.create_subnet")

        self.clients("neutron").create_subnet.reset_mock()

        # Custom options
        extras = {"cidr": "192.168.16.0/24", "allocation_pools": []}
        subnet_data.update(extras)
        expected_subnet_data["subnet"].update(extras)
        scenario._create_subnet(network, subnet_data)
        self.clients("neutron").create_subnet.assert_called_once_with(
            expected_subnet_data)
Exemplo n.º 3
0
    def test_update_subnet(self):
        scenario = utils.NeutronScenario(context=self.context)
        scenario._generate_random_name = mock.Mock()
        expected_subnet = {
            "subnet": {
                "name": scenario._generate_random_name.return_value,
                "enable_dhcp": False,
                "fakearg": "fake"
            }
        }
        self.clients("neutron").update_subnet.return_value = expected_subnet

        subnet = {"subnet": {"name": "subnet-name", "id": "subnet-id"}}
        subnet_update_args = {
            "name": "foo",
            "enable_dhcp": False,
            "fakearg": "fake"
        }

        result_subnet = scenario._update_subnet(subnet, subnet_update_args)
        self.clients("neutron").update_subnet.assert_called_once_with(
            subnet["subnet"]["id"], expected_subnet)
        self.assertEqual(result_subnet, expected_subnet)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_subnet")
Exemplo n.º 4
0
    def test_update_port(self):
        scenario = utils.NeutronScenario(context=self.context)
        scenario._generate_random_name = mock.Mock()

        expected_port = {
            "port": {
                "name": scenario._generate_random_name.return_value,
                "admin_state_up": False,
                "fakearg": "fake"
            }
        }
        self.clients("neutron").update_port.return_value = expected_port

        port = {
            "port": {
                "id": "port-id",
                "name": "port-name",
                "admin_state_up": True
            }
        }
        port_update_args = {
            "name": "_updated",
            "admin_state_up": False,
            "fakearg": "fake"
        }

        result_port = scenario._update_port(port, port_update_args)
        self.clients("neutron").update_port.assert_called_once_with(
            port["port"]["id"], expected_port)
        self.assertEqual(result_port, expected_port)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_port")
Exemplo n.º 5
0
    def test_create_network_and_subnets(self, mock__create_network,
                                        mock__create_subnet):
        scenario = utils.NeutronScenario(context=self.context)
        network_create_args = {}
        subnet_create_args = {}
        subnets_per_network = 4

        # Default options
        scenario._create_network_and_subnets(
            network_create_args=network_create_args,
            subnet_create_args=subnet_create_args,
            subnets_per_network=subnets_per_network)

        mock__create_network.assert_called_once_with({})
        mock__create_subnet.assert_has_calls(
            [mock.call({"network": {
                "id": "fake-id"
            }}, {}, "1.0.0.0/24")] * subnets_per_network)

        mock__create_network.reset_mock()
        mock__create_subnet.reset_mock()

        # Custom options
        scenario._create_network_and_subnets(
            network_create_args=network_create_args,
            subnet_create_args={"allocation_pools": []},
            subnet_cidr_start="10.10.10.0/24",
            subnets_per_network=subnets_per_network)

        mock__create_network.assert_called_once_with({})
        mock__create_subnet.assert_has_calls([
            mock.call({"network": {
                "id": "fake-id"
            }}, {"allocation_pools": []}, "10.10.10.0/24")
        ] * subnets_per_network)
Exemplo n.º 6
0
    def test_create_network(self, mock__generate_random_name):
        neutron_scenario = utils.NeutronScenario()
        explicit_name = "explicit_name"
        random_name = "random_name"
        mock__generate_random_name.return_value = random_name
        self.clients("neutron").create_network.return_value = self.network

        # Network name is specified
        network_data = {"name": explicit_name, "admin_state_up": False}
        expected_network_data = {"network": network_data}
        network = neutron_scenario._create_network(network_data)
        self.clients("neutron").create_network.assert_called_once_with(
            expected_network_data)
        self.assertEqual(self.network, network)
        self._test_atomic_action_timer(neutron_scenario.atomic_actions(),
                                       "neutron.create_network")

        self.clients("neutron").create_network.reset_mock()

        # Network name is random generated
        network_data = {"admin_state_up": False}
        expected_network_data["network"]["name"] = random_name
        network = neutron_scenario._create_network(network_data)
        self.clients("neutron").create_network.assert_called_once_with(
            expected_network_data)
Exemplo n.º 7
0
    def test_update_port(self):
        scenario = utils.NeutronScenario()
        expected_port = {
            "port": {
                "name": "port-name_updated",
                "admin_state_up": False,
                "device_id": "dummy_id",
                "device_owner": "dummy_owner"
            }
        }
        self.clients("neutron").update_port.return_value = expected_port

        port = {
            "port": {
                "id": "port-id",
                "name": "port-name",
                "admin_state_up": True
            }
        }
        port_update_args = {
            "name": "_updated",
            "admin_state_up": False,
            "device_id": "dummy_id",
            "device_owner": "dummy_owner"
        }

        result_port = scenario._update_port(port, port_update_args)
        self.clients("neutron").update_port.assert_called_once_with(
            port["port"]["id"], expected_port)
        self.assertEqual(result_port, expected_port)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_port")
Exemplo n.º 8
0
    def test_create_router(self, mock__generate_random_name):
        scenario = utils.NeutronScenario()
        router = mock.Mock()
        explicit_name = "explicit_name"
        random_name = "random_name"
        mock__generate_random_name.return_value = random_name
        self.clients("neutron").create_router.return_value = router

        # Default options
        result_router = scenario._create_router({})
        self.clients("neutron").create_router.assert_called_once_with(
            {"router": {
                "name": random_name
            }})
        self.assertEqual(result_router, router)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.create_router")

        self.clients("neutron").create_router.reset_mock()

        # Custom options
        router_data = {"name": explicit_name, "admin_state_up": True}
        result_router = scenario._create_router(router_data)
        self.clients("neutron").create_router.assert_called_once_with(
            {"router": router_data})
Exemplo n.º 9
0
    def test_update_router(self):
        scenario = utils.NeutronScenario()
        expected_router = {
            "router": {
                "name": "router-name_updated",
                "admin_state_up": False
            }
        }
        self.clients("neutron").update_router.return_value = expected_router

        router = {
            "router": {
                "id": "router-id",
                "name": "router-name",
                "admin_state_up": True
            }
        }
        router_update_args = {"name": "_updated", "admin_state_up": False}

        result_router = scenario._update_router(router, router_update_args)
        self.clients("neutron").update_router.assert_called_once_with(
            router["router"]["id"], expected_router)
        self.assertEqual(result_router, expected_router)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_router")
Exemplo n.º 10
0
    def test_update_network(self):
        scenario = utils.NeutronScenario(context=self.context)
        scenario._generate_random_name = mock.Mock()

        expected_network = {
            "network": {
                "name": scenario._generate_random_name.return_value,
                "admin_state_up": False,
                "fakearg": "fake"
            }
        }
        self.clients("neutron").update_network.return_value = expected_network

        network = {"network": {"name": "network-name", "id": "network-id"}}
        network_update_args = {
            "name": "foo",
            "admin_state_up": False,
            "fakearg": "fake"
        }

        result_network = scenario._update_network(network, network_update_args)
        self.clients("neutron").update_network.assert_called_once_with(
            network["network"]["id"], expected_network)
        self.assertEqual(result_network, expected_network)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_network")
Exemplo n.º 11
0
    def test_update_security_group(self):
        scenario = utils.NeutronScenario()

        security_group = {
            "security_group": {
                "id": "security-group-id",
                "description": "Not updated"
            }
        }
        expected_security_group = {
            "security_group": {
                "id": "security-group-id",
                "description": "Updated"
            }
        }
        security_group_update_args = {"description": "Updated"}
        security_group_update_data = {
            "security_group": security_group_update_args
        }
        self.clients("neutron").update_security_group = mock.Mock(
            return_value=expected_security_group)
        result_security_group = scenario._update_security_group(
            security_group, **security_group_update_args)
        self.clients("neutron").update_security_group.assert_called_once_with(
            security_group["security_group"]["id"], security_group_update_data)
        self.assertEqual(result_security_group, expected_security_group)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_security_group")
Exemplo n.º 12
0
    def test_create_security_group(self, mock_generate_random_name):
        neutron_scenario = utils.NeutronScenario(self.context)
        random_name = "random_name"
        security_group_create_args = {"description": "Fake security group"}
        expected_security_group = {
            "security_group": {
                "id": "fake-id",
                "name": random_name,
                "description": "Fake security group"
            }
        }
        mock_generate_random_name.return_value = random_name
        self.clients("neutron").create_security_group = mock.Mock(
            return_value=expected_security_group)

        security_group_data = {
            "security_group": {
                "name": "random_name",
                "description": "Fake security group"
            }
        }
        resultant_security_group = neutron_scenario._create_security_group(
            **security_group_create_args)
        self.assertEqual(expected_security_group, resultant_security_group)
        self.clients("neutron").create_security_group.assert_called_once_with(
            security_group_data)
        self._test_atomic_action_timer(neutron_scenario.atomic_actions(),
                                       "neutron.create_security_group")
Exemplo n.º 13
0
    def test__get_network_id(self):
        neutron_scenario = utils.NeutronScenario()
        networks = [{
            "id": "foo-id",
            "name": "foo-network"
        }, {
            "id": "bar-id",
            "name": "bar-network"
        }]
        network_id = "foo-id"

        # Valid network-name
        network = "foo-network"
        neutron_scenario._list_networks = mock.Mock(return_value=networks)
        resultant_network_id = neutron_scenario._get_network_id(network)
        self.assertEqual(network_id, resultant_network_id)
        neutron_scenario._list_networks.assert_called_once_with(
            atomic_action=False)

        neutron_scenario._list_networks.reset_mock()

        # Valid network-id
        network = "foo-id"
        resultant_network_id = neutron_scenario._get_network_id(network)
        self.assertEqual(network_id, resultant_network_id)
        neutron_scenario._list_networks.assert_called_once_with(
            atomic_action=False)
        neutron_scenario._list_networks.reset_mock()

        # Invalid network-name
        network = "absent-network"
        self.assertRaises(exceptions.NotFoundException,
                          neutron_scenario._get_network_id, network)
        neutron_scenario._list_networks.assert_called_once_with(
            atomic_action=False)
Exemplo n.º 14
0
 def test__create_lb_pool(self,
                          subnet_id=None,
                          atomic_action=True,
                          pool_create_args=None):
     neutron_scenario = utils.NeutronScenario(self.context)
     pool = {"pool": {"id": "pool-id"}}
     pool_create_args = pool_create_args or {}
     if pool_create_args.get("name") is None:
         neutron_scenario._generate_random_name = mock.Mock(
             return_value="random_name")
     self.clients("neutron").create_pool.return_value = pool
     args = {
         "lb_method": "ROUND_ROBIN",
         "protocol": "HTTP",
         "name": "random_name",
         "subnet_id": subnet_id
     }
     args.update(pool_create_args)
     expected_pool_data = {"pool": args}
     resultant_pool = neutron_scenario._create_lb_pool(
         subnet_id=subnet_id,
         atomic_action=atomic_action,
         **pool_create_args)
     self.assertEqual(resultant_pool, pool)
     self.clients("neutron").create_pool.assert_called_once_with(
         expected_pool_data)
     if atomic_action:
         self._test_atomic_action_timer(neutron_scenario.atomic_actions(),
                                        "neutron.create_pool")
Exemplo n.º 15
0
 def test_list_ports(self):
     scenario = utils.NeutronScenario(context=self.context)
     ports = [{"name": "port1"}, {"name": "port2"}]
     self.clients("neutron").list_ports.return_value = {"ports": ports}
     self.assertEqual(ports, scenario._list_ports())
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.list_ports")
Exemplo n.º 16
0
    def test_create_port(self):
        scenario = utils.NeutronScenario(self.context)
        scenario._generate_random_name = mock.Mock()

        net_id = "network-id"
        net = {"network": {"id": net_id}}
        expected_port_args = {
            "port": {
                "network_id": net_id,
                "name": scenario._generate_random_name.return_value
            }
        }

        # Defaults
        port_create_args = {}
        scenario._create_port(net, port_create_args)
        self.clients("neutron").create_port.assert_called_once_with(
            expected_port_args)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.create_port")

        self.clients("neutron").create_port.reset_mock()

        # Custom options
        port_args = {"admin_state_up": True}
        expected_port_args["port"].update(port_args)
        scenario._create_port(net, port_args)
        self.clients("neutron").create_port.assert_called_once_with(
            expected_port_args)
Exemplo n.º 17
0
    def test_update_pool(self):
        scenario = utils.NeutronScenario(context=self.context)
        scenario._generate_random_name = mock.Mock()

        expected_pool = {
            "pool": {
                "name": scenario._generate_random_name.return_value,
                "admin_state_up": False,
                "fakearg": "fake"
            }
        }
        self.clients("neutron").update_pool.return_value = expected_pool

        pool = {"pool": {"name": "pool-name", "id": "pool-id"}}
        pool_update_args = {
            "name": "foo",
            "admin_state_up": False,
            "fakearg": "fake"
        }

        result_pool = scenario._update_v1_pool(pool, **pool_update_args)
        self.assertEqual(result_pool, expected_pool)
        self.clients("neutron").update_pool.assert_called_once_with(
            pool["pool"]["id"], expected_pool)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.update_pool")
Exemplo n.º 18
0
 def test_delete_v1_healthmonitor(self):
     scenario = utils.NeutronScenario()
     healthmonitor = {"health_monitor": {"id": "fake-id"}}
     scenario._delete_v1_healthmonitor(healthmonitor["health_monitor"])
     self.clients("neutron").delete_health_monitor.assert_called_once_with(
         healthmonitor["health_monitor"]["id"])
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.delete_healthmonitor")
Exemplo n.º 19
0
    def test_delete_network(self):
        scenario = utils.NeutronScenario(context=self.context)

        network_create_args = {}
        network = scenario._create_network(network_create_args)
        scenario._delete_network(network)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.delete_network")
Exemplo n.º 20
0
 def test_delete_router(self):
     scenario = utils.NeutronScenario(context=self.context)
     router = scenario._create_router({})
     scenario._delete_router(router)
     self.clients("neutron").delete_router.assert_called_once_with(
         router["router"]["id"])
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.delete_router")
Exemplo n.º 21
0
    def setUp(self):
        super(NeutronScenarioTestCase, self).setUp()
        self.network = mock.Mock()
        self.scenario = utils.NeutronScenario(self.context)

        self.random_name = "random_name"
        self.scenario.generate_random_name = mock.Mock(
            return_value=self.random_name)
Exemplo n.º 22
0
 def test_list_routers(self):
     scenario = utils.NeutronScenario(context=self.context)
     routers = [mock.Mock()]
     self.clients("neutron").list_routers.return_value = {
         "routers": routers}
     self.assertEqual(routers, scenario._list_routers())
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.list_routers")
Exemplo n.º 23
0
    def test_delete_subnet(self):
        scenario = utils.NeutronScenario()

        network = scenario._create_network({})
        subnet = scenario._create_subnet(network, {})
        scenario._delete_subnet(subnet)

        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.delete_subnet")
Exemplo n.º 24
0
    def test_delete_v1_vip(self):
        scenario = utils.NeutronScenario()

        vip = {"vip": {"id": "fake-id"}}
        scenario._delete_v1_vip(vip["vip"])
        self.clients("neutron").delete_vip.assert_called_once_with(
            vip["vip"]["id"])
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.delete_vip")
Exemplo n.º 25
0
 def test_list_networks(self):
     scenario = utils.NeutronScenario()
     networks_list = []
     networks_dict = {"networks": networks_list}
     self.clients("neutron").list_networks.return_value = networks_dict
     return_networks_list = scenario._list_networks()
     self.assertEqual(networks_list, return_networks_list)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.list_networks")
Exemplo n.º 26
0
 def test_list_v1_vips(self):
     scenario = utils.NeutronScenario()
     vips_list = []
     vips_dict = {"vips": vips_list}
     self.clients("neutron").list_vips.return_value = vips_dict
     return_vips_dict = scenario._list_v1_vips()
     self.assertEqual(vips_dict, return_vips_dict)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.list_vips")
Exemplo n.º 27
0
 def test_list_v1_pools(self):
     scenario = utils.NeutronScenario(context=self.context)
     pools_list = []
     pools_dict = {"pools": pools_list}
     self.clients("neutron").list_pools.return_value = pools_dict
     return_pools_dict = scenario._list_v1_pools()
     self.assertEqual(pools_dict, return_pools_dict)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.list_pools")
Exemplo n.º 28
0
    def test_delete_port(self):
        scenario = utils.NeutronScenario(context=self.context)

        network = scenario._create_network({})
        port = scenario._create_port(network, {})
        scenario._delete_port(port)

        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.create_port")
Exemplo n.º 29
0
    def test_delete_v1_pool(self):
        scenario = utils.NeutronScenario(context=self.context)

        pool = {"pool": {"id": "fake-id"}}
        scenario._delete_v1_pool(pool["pool"])
        self.clients("neutron").delete_pool.assert_called_once_with(
            pool["pool"]["id"])
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "neutron.delete_pool")
Exemplo n.º 30
0
 def test_list_floating_ips(self):
     scenario = utils.NeutronScenario()
     fips_list = [{"id": "floating-ip-id"}]
     fips_dict = {"floatingips": fips_list}
     self.clients("neutron").list_floatingips.return_value = fips_dict
     self.assertEqual(scenario._list_floating_ips(),
                      self.clients("neutron").list_floatingips.return_value)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "neutron.list_floating_ips")