Beispiel #1
0
 def _delete_floating_ip(self, server, fip):
     with logging.ExceptionLogger(LOG,
                                  "Unable to delete IP: %s" % fip["ip"]):
         if self.check_ip_address(fip["ip"])(server):
             self._dissociate_floating_ip(server, fip["ip"])
             with atomic.ActionTimer(self, "neutron.delete_floating_ip"):
                 network_wrapper.wrap(self.clients,
                                      self).delete_floating_ip(fip["id"],
                                                               wait=True)
Beispiel #2
0
    def _remove_default_security_group(self):
        """Delete default security group for tenants."""
        clients = osclients.Clients(self.credential)

        if consts.Service.NEUTRON not in clients.services().values():
            return

        use_sg, msg = network.wrap(clients,
                                   self).supports_extension("security-group")
        if not use_sg:
            LOG.debug("Security group context is disabled: %s" % msg)
            return

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            with logging.ExceptionLogger(
                    LOG, "Unable to delete default security group"):
                uclients = osclients.Clients(user["credential"])
                security_groups = uclients.neutron()\
                    .list_security_groups(tenant_id=tenant_id)
                default = [
                    sg for sg in security_groups["security_groups"]
                    if sg["name"] == "default"
                ]
                if default:
                    clients.neutron().delete_security_group(default[0]["id"])
Beispiel #3
0
 def setup(self):
     # NOTE(rkiran): Some clients are not thread-safe. Thus during
     #               multithreading/multiprocessing, it is likely the
     #               sockets are left open. This problem is eliminated by
     #               creating a connection in setup and cleanup separately.
     net_wrapper = network_wrapper.wrap(osclients.Clients(
         self.context["admin"]["credential"]),
                                        self,
                                        config=self.config)
     kwargs = {}
     if self.config["dns_nameservers"] is not None:
         kwargs["dns_nameservers"] = self.config["dns_nameservers"]
     for user, tenant_id in (utils.iterate_per_tenants(
             self.context.get("users", []))):
         self.context["tenants"][tenant_id]["networks"] = []
         for i in range(self.config["networks_per_tenant"]):
             # NOTE(amaretskiy): router_create_args and subnets_num take
             #                   effect for Neutron only.
             network_create_args = self.config["network_create_args"].copy()
             network = net_wrapper.create_network(
                 tenant_id,
                 dualstack=self.config["dualstack"],
                 subnets_num=self.config["subnets_per_network"],
                 network_create_args=network_create_args,
                 router_create_args=self.config["router"],
                 **kwargs)
             self.context["tenants"][tenant_id]["networks"].append(network)
 def __init__(self, ctx):
     super(PrepareEC2ClientContext, self).__init__(ctx)
     self.net_wrapper = network_wrapper.wrap(osclients.Clients(
         self.context["admin"]["credential"]),
                                             self,
                                             config=self.config)
     self.net_wrapper.start_cidr = '10.0.0.0/16'
 def setup(self):
     self.ports = []
     net_wrapper = network_wrapper.wrap(osclients.Clients(
         self.context["admin"]["credential"]),
                                        self,
                                        config=self.config)
     for user, tenant_id in (utils.iterate_per_tenants(
             self.context.get("users", []))):
         # Generate FAKE SG that would only have some fake ports.
         sg_name = 'sg-remote-%s' % tenant_id
         self.remote_sg = _prepare_remote_sg(user, sg_name)
         if not self.config.get('create_ports'):
             break
         neutron = osclients.Clients(user['credential']).neutron()
         subnet_id = self.context["tenants"][tenant_id]["networks"][0][
             'subnets'][0]
         subnet = neutron.show_subnet(subnet_id)
         for i in range(0, self.config['num_of_ports']):
             port = {
                 'port': {
                     'binding:host_id':
                     RemoteScurityGroup.COMPUTE_HOST,
                     'name':
                     "remote_sg_port-%i" % i,
                     'security_groups': [self.remote_sg['id']],
                     'network_id':
                     self.context["tenants"][tenant_id]["networks"][0]['id']
                 }
             }
             port = neutron.create_port(port)
             self.bind_port(port, subnet, neutron)
             self.ports.append(port)
 def setup(self):
     net_wrapper = network_wrapper.wrap(
         osclients.Clients(self.context["admin"]["credential"]),
         self, config=self.config)
     for user, tenant_id in (utils.iterate_per_tenants(
             self.context.get("users", []))):
         remote_sg_name = 'sg-remote-%s' % tenant_id
         _prepare_rules(user, remote_sg_name, self.config['num_of_rules']) 
 def setup(self):
     for user, tenant_id in utils.iterate_per_tenants(
             self.context.get("users", [])):
         net_wrapper = network_wrapper.wrap(osclients.Clients(
             user["credential"]),
                                            self,
                                            config=self.config)
         self.context["tenants"][tenant_id]["networks"] = (
             net_wrapper.list_networks())
Beispiel #8
0
 def cleanup(self):
     net_wrapper = network_wrapper.wrap(
         osclients.Clients(self.context["admin"]["credential"]),
         self, config=self.config)
     for tenant_id, tenant_ctx in self.context["tenants"].items():
         for network in tenant_ctx.get("networks", []):
             with logging.ExceptionLogger(
                     LOG,
                     "Failed to delete network for tenant %s" % tenant_id):
                 net_wrapper.delete_network(network)
Beispiel #9
0
    def test_wrap(self):
        mock_clients = mock.Mock()
        mock_clients.nova().networks.list.return_value = []
        config = {"fakearg": "fake"}
        owner = Owner()

        mock_clients.services.return_value = {"foo": consts.Service.NEUTRON}
        wrapper = network.wrap(mock_clients, owner, config)
        self.assertIsInstance(wrapper, network.NeutronWrapper)
        self.assertEqual(wrapper.owner, owner)
        self.assertEqual(wrapper.config, config)
Beispiel #10
0
    def _attach_floating_ip(self, server, floating_network):
        internal_network = list(server.networks)[0]
        fixed_ip = server.addresses[internal_network][0]["addr"]

        with atomic.ActionTimer(self, "neutron.create_floating_ip"):
            fip = network_wrapper.wrap(self.clients, self).create_floating_ip(
                ext_network=floating_network,
                tenant_id=server.tenant_id,
                fixed_ip=fixed_ip)

        self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip)

        return fip
Beispiel #11
0
 def cleanup(self):
     net_wrapper = network_wrapper.wrap(osclients.Clients(
         self.context["admin"]["credential"]),
                                        self,
                                        config=self.config)
     for tenant_id, tenant_ctx in self.context["tenants"].items():
         for network in tenant_ctx.get("networks", []):
             for pool in network.get("lb_pools", []):
                 with logging.ExceptionLogger(
                         LOG, "Failed to delete pool %(pool)s for tenant "
                         "%(tenant)s" % {
                             "pool": pool["pool"]["id"],
                             "tenant": tenant_id
                         }):
                     if self.config["lbaas_version"] == 1:
                         net_wrapper.delete_v1_pool(pool["pool"]["id"])
    def setup(self):
        admin_or_user = (self.context.get("admin")
                         or self.context.get("users")[0])

        net_wrapper = network.wrap(osclients.Clients(
            admin_or_user["credential"]),
                                   self,
                                   config=self.config)
        use_sg, msg = net_wrapper.supports_extension("security-group")
        if not use_sg:
            LOG.info("Security group context is disabled: %s" % msg)
            return

        secgroup_name = self.generate_random_name()
        for user in self.context["users"]:
            user["secgroup"] = _prepare_open_secgroup(user["credential"],
                                                      secgroup_name)
Beispiel #13
0
    def setup(self):
        net_wrapper = network_wrapper.wrap(osclients.Clients(
            self.context["admin"]["credential"]),
                                           self,
                                           config=self.config)

        use_lb, msg = net_wrapper.supports_extension("lbaas")
        if not use_lb:
            LOG.info(msg)
            return

        # Creates a lb-pool for every subnet created in network context.
        for user, tenant_id in (utils.iterate_per_tenants(
                self.context.get("users", []))):
            for network in self.context["tenants"][tenant_id]["networks"]:
                for subnet in network.get("subnets", []):
                    if self.config["lbaas_version"] == 1:
                        network.setdefault("lb_pools", []).append(
                            net_wrapper.create_v1_pool(tenant_id, subnet,
                                                       **self.config["pool"]))
                    else:
                        raise NotImplementedError(
                            "Context for LBaaS version %s not implemented." %
                            self.config["lbaas_version"])