Ejemplo n.º 1
0
    def _setUp(self):
        self.user = base.get_rand_name(prefix="user")
        self.password = base.get_rand_name(prefix="pass")
        self.vhost = base.get_rand_name(prefix="vhost")

        self._execute("add_user", self.user, self.password)
        self.addCleanup(self._execute, "delete_user", self.user)

        self._execute("add_vhost", self.vhost)
        self.addCleanup(self._execute, "delete_vhost", self.vhost)

        self._execute("set_permissions", "-p", self.vhost, self.user, ".*", ".*", ".*")
Ejemplo n.º 2
0
    def _setUp(self):
        self.user = base.get_rand_name(prefix='user')
        self.password = base.get_rand_name(prefix='pass')
        self.vhost = base.get_rand_name(prefix='vhost')

        self._execute('add_user', self.user, self.password)
        self.addCleanup(self._execute, 'delete_user', self.user)

        self._execute('add_vhost', self.vhost)
        self.addCleanup(self._execute, 'delete_vhost', self.vhost)

        self._execute('set_permissions', '-p', self.vhost, self.user, '.*',
                      '.*', '.*')
Ejemplo n.º 3
0
    def _setUp(self):
        self.user = base.get_rand_name(prefix='user')
        self.password = base.get_rand_name(prefix='pass')
        self.vhost = base.get_rand_name(prefix='vhost')

        self._execute('add_user', self.user, self.password)
        self.addCleanup(self._execute, 'delete_user', self.user)

        self._execute('add_vhost', self.vhost)
        self.addCleanup(self._execute, 'delete_vhost', self.vhost)

        self._execute('set_permissions', '-p', self.vhost, self.user,
                      '.*', '.*', '.*')
Ejemplo n.º 4
0
    def setUp(self):
        super(RabbitmqEnvironmentFixture, self).setUp()

        self.user = base.get_rand_name(prefix='user')
        self.password = base.get_rand_name(prefix='pass')
        self.vhost = base.get_rand_name(prefix='vhost')

        self._execute('add_user', self.user, self.password)
        self.addCleanup(self._execute, 'delete_user', self.user)

        self._execute('add_vhost', self.vhost)
        self.addCleanup(self._execute, 'delete_vhost', self.vhost)

        self._execute('set_permissions', '-p', self.vhost, self.user,
                      '.*', '.*', '.*')
Ejemplo n.º 5
0
    def create_router(self, tenant_id, name=None, ha=False):
        resource_type = 'router'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 6
0
    def create_network(self, tenant_id, name=None):
        resource_type = "network"

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {"tenant_id": tenant_id, "name": name}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 7
0
    def create_router(self, tenant_id, name=None, ha=False):
        resource_type = "router"

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {"tenant_id": tenant_id, "name": name, "ha": ha}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 8
0
    def create_network(self, tenant_id, name=None, external=False):
        resource_type = 'network'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}
        spec['router:external'] = external
        return self._create_resource(resource_type, spec)
Ejemplo n.º 9
0
    def create_network(self, tenant_id, name=None):
        resource_type = 'network'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 10
0
    def create_router(self, tenant_id, name=None, ha=False):
        resource_type = 'router'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 11
0
    def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
        device_mtu = 1450

        # Create a new OVS bridge
        ovs_bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.assertFalse(ovs_bridge.get_port_name_list())

        # Add a new linuxbridge port with reduced MTU to OVS bridge
        lb_bridge = self.useFixture(
            net_helpers.LinuxBridgeFixture()).bridge
        lb_bridge_port = self.useFixture(
            net_helpers.LinuxBridgePortFixture(lb_bridge))
        lb_bridge_port.port.link.set_mtu(device_mtu - 1)
        ovs_bridge.add_port(lb_bridge_port.port.name)

        # Now plug a device with intended MTU that is higher than for the port
        # above and validate that its MTU is not reduced to the least MTU on
        # the bridge
        device_name = tests_base.get_rand_name()
        mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=ovs_bridge.br_name,
                            namespace=namespace,
                            mtu=device_mtu)

        self.assertIn(device_name, ovs_bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
        self.assertEqual(
            device_mtu,
            ip_lib.IPDevice(device_name, namespace=namespace).link.mtu
        )
Ejemplo n.º 12
0
    def create_network(self, tenant_id, name=None):
        resource_type = 'network'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 13
0
    def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
        device_mtu = 1450

        # Create a new OVS bridge
        ovs_bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.assertFalse(ovs_bridge.get_port_name_list())

        # Add a new linuxbridge port with reduced MTU to OVS bridge
        lb_bridge = self.useFixture(net_helpers.LinuxBridgeFixture()).bridge
        lb_bridge_port = self.useFixture(
            net_helpers.LinuxBridgePortFixture(lb_bridge))
        lb_bridge_port.port.link.set_mtu(device_mtu - 1)
        ovs_bridge.add_port(lb_bridge_port.port.name)

        # Now plug a device with intended MTU that is higher than for the port
        # above and validate that its MTU is not reduced to the least MTU on
        # the bridge
        device_name = tests_base.get_rand_name()
        mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=ovs_bridge.br_name,
                            namespace=namespace,
                            mtu=device_mtu)

        self.assertIn(device_name, ovs_bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
        self.assertEqual(
            device_mtu,
            ip_lib.IPDevice(device_name, namespace=namespace).link.mtu)
Ejemplo n.º 14
0
    def create_network(self, tenant_id, name=None, external=False):
        resource_type = 'network'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}
        spec['router:external'] = external
        return self._create_resource(resource_type, spec)
Ejemplo n.º 15
0
def create_resource(prefix, creation_func, *args, **kwargs):
    """Create a new resource that does not already exist.

    If prefix isn't 'max_length' in size, a random suffix is concatenated to
    ensure it is random. Otherwise, 'prefix' is used as is.

    :param prefix: The prefix for a randomly generated name
    :param creation_func: A function taking the name of the resource
           to be created as it's first argument.  An error is assumed
           to indicate a name collision.
    :param *args *kwargs: These will be passed to the create function.
    """

    # Don't generate a random name if prefix is already full-length.
    if len(prefix) == n_const.DEVICE_NAME_MAX_LEN:
        return creation_func(prefix, *args, **kwargs)

    while True:
        name = base.get_rand_name(
            max_length=n_const.DEVICE_NAME_MAX_LEN,
            prefix=prefix)
        try:
            return creation_func(name, *args, **kwargs)
        except RuntimeError:
            pass
Ejemplo n.º 16
0
    def create_subnet(self,
                      tenant_id,
                      network_id,
                      cidr,
                      gateway_ip=None,
                      name=None,
                      enable_dhcp=True,
                      ipv6_address_mode='slaac',
                      ipv6_ra_mode='slaac'):
        resource_type = 'subnet'

        name = name or base.get_rand_name(prefix=resource_type)
        ip_version = netaddr.IPNetwork(cidr).version
        spec = {
            'tenant_id': tenant_id,
            'network_id': network_id,
            'name': name,
            'cidr': cidr,
            'enable_dhcp': enable_dhcp,
            'ip_version': ip_version
        }
        if ip_version == constants.IP_VERSION_6:
            spec['ipv6_address_mode'] = ipv6_address_mode
            spec['ipv6_ra_mode'] = ipv6_ra_mode

        if gateway_ip:
            spec['gateway_ip'] = gateway_ip

        return self._create_resource(resource_type, spec)
Ejemplo n.º 17
0
    def create_router(self, tenant_id, name=None, ha=False,
                      external_network=None):
        resource_type = 'router'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}
        if external_network:
            spec['external_gateway_info'] = {"network_id": external_network}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 18
0
    def create_router(self, tenant_id, name=None, ha=False,
                      external_network=None):
        resource_type = 'router'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}
        if external_network:
            spec['external_gateway_info'] = {"network_id": external_network}

        return self._create_resource(resource_type, spec)
Ejemplo n.º 19
0
    def create_subnet(self, tenant_id, network_id,
                      cidr, gateway_ip=None, ip_version=4,
                      name=None, enable_dhcp=True):
        resource_type = 'subnet'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'network_id': network_id, 'name': name,
                'cidr': cidr, 'ip_version': ip_version,
                'enable_dhcp': enable_dhcp}
        if gateway_ip:
            spec['gateway_ip'] = gateway_ip

        return self._create_resource(resource_type, spec)
Ejemplo n.º 20
0
    def create_subnet(self, tenant_id, network_id,
                      cidr, gateway_ip=None, ip_version=4,
                      name=None, enable_dhcp=True):
        resource_type = 'subnet'

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'network_id': network_id, 'name': name,
                'cidr': cidr, 'ip_version': ip_version,
                'enable_dhcp': enable_dhcp}
        if gateway_ip:
            spec['gateway_ip'] = gateway_ip

        return self._create_resource(resource_type, spec)
Ejemplo n.º 21
0
    def _setUp(self):
        super(OVSPortFixture, self)._setUp()

        # because in some tests this port can be used to providing connection
        # between linuxbridge agents and vlan_id can be also added to this
        # device name it has to be max LB_DEVICE_NAME_MAX_LEN long
        port_name = tests_base.get_rand_name(LB_DEVICE_NAME_MAX_LEN,
                                             PORT_PREFIX)

        if self.hybrid_plug:
            self.hybrid_plug_port(port_name)
        else:
            self.plug_port(port_name)
Ejemplo n.º 22
0
 def test_network_lifecycle(self):
     net = self.client.create_network(name=tests_base.get_rand_name())
     listed_networks = {x.id: x.name for x in self.client.get_networks()}
     self.assertIn(net.id, listed_networks)
     self.assertEqual(listed_networks[net.id], net.name,
                      'Listed network name is not as expected.')
     updated_name = 'new %s' % net.name
     updated_net = self.client.update_network(net.id, name=updated_name)
     self.assertEqual(updated_name, updated_net.name,
                      'Updated network name is not as expected.')
     self.client.delete_network(net.id)
     with testtools.ExpectedException(self.client.NotFound,
                                      msg='Network was not deleted'):
         self.client.get_network(net.id)
Ejemplo n.º 23
0
 def test_network_lifecycle(self):
     net = self.client.create_network(name=tests_base.get_rand_name())
     listed_networks = {x.id: x.name for x in self.client.get_networks()}
     self.assertIn(net.id, listed_networks)
     self.assertEqual(listed_networks[net.id], net.name,
                      'Listed network name is not as expected.')
     updated_name = 'new %s' % net.name
     updated_net = self.client.update_network(net.id, name=updated_name)
     self.assertEqual(updated_name, updated_net.name,
                      'Updated network name is not as expected.')
     self.client.delete_network(net.id)
     with testtools.ExpectedException(self.client.NotFound,
                                      msg='Network was not deleted'):
         self.client.get_network(net.id)
Ejemplo n.º 24
0
    def test_plug_succeeds(self):
        device_name = tests_base.get_rand_name()
        mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name
        bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge

        self.assertFalse(bridge.get_port_name_list())
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=bridge.br_name,
                            namespace=namespace)
        self.assertIn(device_name, bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
Ejemplo n.º 25
0
    def _setUp(self):
        super(OVSPortFixture, self)._setUp()

        # because in some tests this port can be used to providing connection
        # between linuxbridge agents and vlan_id can be also added to this
        # device name it has to be max LB_DEVICE_NAME_MAX_LEN long
        port_name = tests_base.get_rand_name(
            LB_DEVICE_NAME_MAX_LEN,
            PORT_PREFIX
        )

        if self.hybrid_plug:
            self.hybrid_plug_port(port_name)
        else:
            self.plug_port(port_name)
Ejemplo n.º 26
0
def create_resource(prefix, creation_func, *args, **kwargs):
    """Create a new resource that does not already exist.

    :param prefix: The prefix for a randomly generated name
    :param creation_func: A function taking the name of the resource
           to be created as it's first argument.  An error is assumed
           to indicate a name collision.
    :param *args *kwargs: These will be passed to the create function.
    """
    while True:
        name = base.get_rand_name(max_length=n_const.DEVICE_NAME_MAX_LEN,
                                  prefix=prefix)
        try:
            return creation_func(name, *args, **kwargs)
        except RuntimeError:
            pass
Ejemplo n.º 27
0
    def _setUp(self):
        super(OVSPortFixture, self)._setUp()

        interface_config = cfg.ConfigOpts()
        interface_config.register_opts(interface.OPTS)
        ovs_interface = interface.OVSInterfaceDriver(interface_config)

        # because in some tests this port can be used to providing connection
        # between linuxbridge agents and vlan_id can be also added to this
        # device name it has to be max LB_DEVICE_NAME_MAX_LEN long
        port_name = tests_base.get_rand_name(LB_DEVICE_NAME_MAX_LEN, PORT_PREFIX)
        ovs_interface.plug_new(
            None, self.port_id, port_name, self.mac, bridge=self.bridge.br_name, namespace=self.namespace
        )
        self.addCleanup(self.bridge.delete_port, port_name)
        self.port = ip_lib.IPDevice(port_name, self.namespace)
Ejemplo n.º 28
0
    def create_subnet(self, tenant_id, network_id, cidr, gateway_ip=None, ip_version=4, name=None, enable_dhcp=True):
        resource_type = "subnet"

        name = name or base.get_rand_name(prefix=resource_type)
        spec = {
            "tenant_id": tenant_id,
            "network_id": network_id,
            "name": name,
            "cidr": cidr,
            "ip_version": ip_version,
            "enable_dhcp": enable_dhcp,
        }
        if gateway_ip:
            spec["gateway_ip"] = gateway_ip

        return self._create_resource(resource_type, spec)
Ejemplo n.º 29
0
def create_resource(prefix, creation_func, *args, **kwargs):
    """Create a new resource that does not already exist.

    :param prefix: The prefix for a randomly generated name
    :param creation_func: A function taking the name of the resource
           to be created as it's first argument.  An error is assumed
           to indicate a name collision.
    :param *args *kwargs: These will be passed to the create function.
    """
    while True:
        name = base.get_rand_name(
            max_length=n_const.DEVICE_NAME_MAX_LEN,
            prefix=prefix)
        try:
            return creation_func(name, *args, **kwargs)
        except RuntimeError:
            pass
Ejemplo n.º 30
0
    def create_subnet(self, tenant_id, network_id,
                      cidr, gateway_ip=None, name=None, enable_dhcp=True,
                      ipv6_address_mode='slaac', ipv6_ra_mode='slaac'):
        resource_type = 'subnet'

        name = name or base.get_rand_name(prefix=resource_type)
        ip_version = netaddr.IPNetwork(cidr).version
        spec = {'tenant_id': tenant_id, 'network_id': network_id, 'name': name,
                'cidr': cidr, 'enable_dhcp': enable_dhcp,
                'ip_version': ip_version}
        if ip_version == constants.IP_VERSION_6:
            spec['ipv6_address_mode'] = ipv6_address_mode
            spec['ipv6_ra_mode'] = ipv6_ra_mode

        if gateway_ip:
            spec['gateway_ip'] = gateway_ip

        return self._create_resource(resource_type, spec)
Ejemplo n.º 31
0
def create_patch_ports(source, destination):
    """Hook up two OVS bridges.

    The result is two patch ports, each end connected to a bridge.
    The two patch port names will start with 'patch-', followed by identical
    four characters. For example patch-xyzw-fedora, and patch-xyzw-ubuntu,
    where fedora and ubuntu are random strings.

    :param source: Instance of OVSBridge
    :param destination: Instance of OVSBridge
    """
    common = tests_base.get_rand_name(max_length=4, prefix='')
    prefix = '%s-%s-' % (PATCH_PREFIX, common)

    source_name = tests_base.get_rand_device_name(prefix=prefix)
    destination_name = tests_base.get_rand_device_name(prefix=prefix)

    source.add_patch_port(source_name, destination_name)
    destination.add_patch_port(destination_name, source_name)
Ejemplo n.º 32
0
def create_patch_ports(source, destination):
    """Hook up two OVS bridges.

    The result is two patch ports, each end connected to a bridge.
    The two patch port names will start with 'patch-', followed by identical
    four characters. For example patch-xyzw-fedora, and patch-xyzw-ubuntu,
    where fedora and ubuntu are random strings.

    :param source: Instance of OVSBridge
    :param destination: Instance of OVSBridge
    """
    common = tests_base.get_rand_name(max_length=4, prefix='')
    prefix = '%s-%s-' % (PATCH_PREFIX, common)

    source_name = tests_base.get_rand_device_name(prefix=prefix)
    destination_name = tests_base.get_rand_device_name(prefix=prefix)

    source.add_patch_port(source_name, destination_name)
    destination.add_patch_port(destination_name, source_name)
Ejemplo n.º 33
0
    def _setUp(self):
        super(OVSPortFixture, self)._setUp()

        interface_config = cfg.ConfigOpts()
        interface_config.register_opts(interface.OPTS)
        ovs_interface = interface.OVSInterfaceDriver(interface_config)

        # because in some tests this port can be used to providing connection
        # between linuxbridge agents and vlan_id can be also added to this
        # device name it has to be max LB_DEVICE_NAME_MAX_LEN long
        port_name = tests_base.get_rand_name(LB_DEVICE_NAME_MAX_LEN,
                                             PORT_PREFIX)
        ovs_interface.plug_new(None,
                               self.port_id,
                               port_name,
                               self.mac,
                               bridge=self.bridge.br_name,
                               namespace=self.namespace)
        self.addCleanup(self.bridge.delete_port, port_name)
        self.port = ip_lib.IPDevice(port_name, self.namespace)
Ejemplo n.º 34
0
 def _generate_namespace_suffix(self):
     return base.get_rand_name(prefix='test')
Ejemplo n.º 35
0
def get_rand_port_name():
    return tests_base.get_rand_name(max_length=n_const.DEVICE_NAME_MAX_LEN, prefix=PORT_PREFIX)
Ejemplo n.º 36
0
 def _make_bridge(self):
     bridge = framework.get_ovs_bridge(tests_base.get_rand_name())
     bridge.create()
     self.addCleanup(bridge.destroy)
     return bridge
Ejemplo n.º 37
0
 def _make_bridge(self):
     bridge = framework.get_ovs_bridge(tests_base.get_rand_name())
     bridge.create()
     self.addCleanup(bridge.destroy)
     return bridge
Ejemplo n.º 38
0
def get_rand_port_name():
    return tests_base.get_rand_name(max_length=n_const.DEVICE_NAME_MAX_LEN,
                                    prefix=PORT_PREFIX)
Ejemplo n.º 39
0
 def _generate_bridge_mappings(self):
     return ('physnet1:%s' %
             base.get_rand_name(
                 prefix='br-eth',
                 max_length=constants.DEVICE_NAME_MAX_LEN))
Ejemplo n.º 40
0
 def _generate_external_bridge(self):
     return base.get_rand_name(prefix='br-ex',
                               max_length=constants.DEVICE_NAME_MAX_LEN)
Ejemplo n.º 41
0
 def _generate_host(self):
     return base.get_rand_name(prefix='host-')
Ejemplo n.º 42
0
 def _generate_host(self):
     return base.get_rand_name(prefix='host-')
Ejemplo n.º 43
0
 def _generate_external_bridge(self):
     return base.get_rand_name(prefix='br-ex',
                               max_length=constants.DEVICE_NAME_MAX_LEN)
Ejemplo n.º 44
0
 def _generate_integration_bridge(self):
     return base.get_rand_name(prefix='br-int',
                               max_length=constants.DEVICE_NAME_MAX_LEN)
Ejemplo n.º 45
0
 def _generate_bridge_mappings(self):
     return ('physnet1:%s' %
             base.get_rand_name(
                 prefix='br-eth',
                 max_length=constants.DEVICE_NAME_MAX_LEN))
Ejemplo n.º 46
0
 def _generate_namespace_suffix(self):
     return base.get_rand_name(prefix='test')
Ejemplo n.º 47
0
 def _generate_integration_bridge(self):
     return base.get_rand_name(prefix='br-int',
                               max_length=constants.DEVICE_NAME_MAX_LEN)