Exemplo n.º 1
0
 def test_get_extnetwork_env_ok2(self):
     cloud = mock.Mock()
     cloud.get_network.return_value = None
     cloud.list_networks.return_value = None
     os.environ["EXTERNAL_NETWORK"] = 'dummy'
     self.assertEqual(functest_utils.get_external_network(cloud), None)
     cloud.get_network.assert_called_once_with(
         'dummy', {'router:external': True})
     cloud.list_networks.assert_called_once_with(
         {'router:external': True})
Exemplo n.º 2
0
 def test_get_extnetwork_env_ok1(self):
     cloud = mock.Mock()
     cloud.get_network.return_value = munch.Munch(name="dummy")
     os.environ["EXTERNAL_NETWORK"] = 'dummy'
     self.assertEqual(
         functest_utils.get_external_network(cloud),
         cloud.get_network.return_value)
     cloud.get_network.assert_called_once_with(
         'dummy', {'router:external': True})
     cloud.list_networks.assert_not_called()
Exemplo n.º 3
0
 def test_get_extnetwork_noenv_ko(self):
     try:
         del os.environ["EXTERNAL_NETWORK"]
     except Exception:  # pylint: disable=broad-except
         pass
     cloud = mock.Mock()
     cloud.list_networks.return_value = None
     self.assertEqual(functest_utils.get_external_network(cloud), None)
     cloud.get_network.assert_not_called()
     cloud.list_networks.assert_called_once_with(
         {'router:external': True})
Exemplo n.º 4
0
 def __init__(self, **kwargs):
     super(VPingBase, self).__init__(**kwargs)
     self.logger = logging.getLogger(__name__)
     self.cloud = os_client_config.make_shade()
     self.ext_net = functest_utils.get_external_network(self.cloud)
     self.logger.debug("ext_net: %s", self.ext_net)
     self.guid = '-' + str(uuid.uuid4())
     self.network = None
     self.subnet = None
     self.router = None
     self.image = None
     self.flavor = None
     self.vm1 = None
     self.sec1 = None
Exemplo n.º 5
0
 def test_get_extnetwork_nocloud(self):
     with self.assertRaises(AssertionError):
         functest_utils.get_external_network(None)
Exemplo n.º 6
0
    def _prepare_env(self):
        """Create resources needed by test scenarios."""
        assert self.cloud
        LOGGER.debug('Validating the test name...')
        if self.test_name not in self.TESTS:
            raise Exception("Test name '%s' is invalid" % self.test_name)

        network_name = self.RALLY_PRIVATE_NET_NAME + self.guid
        subnet_name = self.RALLY_PRIVATE_SUBNET_NAME + self.guid
        router_name = self.RALLY_ROUTER_NAME + self.guid
        self.image_name = self.GLANCE_IMAGE_NAME + self.guid
        self.flavor_name = self.FLAVOR_NAME + self.guid
        self.flavor_alt_name = self.FLAVOR_ALT_NAME + self.guid
        self.compute_cnt = len(self.cloud.list_hypervisors())
        self.ext_net = functest_utils.get_external_network(self.cloud)
        if self.ext_net is None:
            raise Exception("No external network found")

        LOGGER.debug("Creating image '%s'...", self.image_name)
        self.image = self.cloud.create_image(
            self.image_name,
            filename=self.GLANCE_IMAGE_PATH,
            disk_format=self.GLANCE_IMAGE_FORMAT,
            meta=self.GLANCE_IMAGE_EXTRA_PROPERTIES,
            is_public=True)
        if self.image is None:
            raise Exception("Failed to create image")

        LOGGER.debug("Creating network '%s'...", network_name)
        provider = {}
        if hasattr(config.CONF, 'rally_network_type'):
            provider["network_type"] = getattr(
                config.CONF, 'rally_network_type')
        if hasattr(config.CONF, 'rally_physical_network'):
            provider["physical_network"] = getattr(
                config.CONF, 'rally_physical_network')
        if hasattr(config.CONF, 'rally_segmentation_id'):
            provider["segmentation_id"] = getattr(
                config.CONF, 'rally_segmentation_id')

        self.network = self.cloud.create_network(
            network_name, shared=True, provider=provider)
        if self.network is None:
            raise Exception("Failed to create private network")

        self.subnet = self.cloud.create_subnet(
            self.network.id,
            subnet_name=subnet_name,
            cidr=self.RALLY_PRIVATE_SUBNET_CIDR,
            enable_dhcp=True,
            dns_nameservers=[env.get('NAMESERVER')])
        if self.subnet is None:
            raise Exception("Failed to create private subnet")

        LOGGER.debug("Creating router '%s'...", router_name)
        self.router = self.cloud.create_router(
            router_name, ext_gateway_net_id=self.ext_net.id)
        if self.router is None:
            raise Exception("Failed to create router")
        self.cloud.add_router_interface(self.router, subnet_id=self.subnet.id)

        LOGGER.debug("Creating flavor '%s'...", self.flavor_name)
        self.flavor = self.cloud.create_flavor(
            self.flavor_name, self.FLAVOR_RAM, 1, 1)
        if self.flavor is None:
            raise Exception("Failed to create flavor")
        self.cloud.set_flavor_specs(
            self.flavor.id, self.FLAVOR_EXTRA_SPECS)

        LOGGER.debug("Creating flavor '%s'...", self.flavor_alt_name)
        self.flavor_alt = self.cloud.create_flavor(
            self.flavor_alt_name, self.FLAVOR_RAM_ALT, 1, 1)
        if self.flavor_alt is None:
            raise Exception("Failed to create flavor")
        self.cloud.set_flavor_specs(
            self.flavor_alt.id, self.FLAVOR_EXTRA_SPECS)