Example #1
0
    def test_basic_create_list_show(self):
        netpartition1_name = get_random_name()

        self.create_and_verify(netpartition1_name, clean_up=False)
        self.list_and_verify(netpartition1_name)
        self.show_and_verify(netpartition1_name)
        delete_and_verify(self, 'nuage netpartition', netpartition1_name)
    def test_nuage_redirect_target_option(self):
        # Note that this test only checks one redirect target per port
        # as it is unclear how to add multiple redirect targets at the moment

        # create RedirectionTarget instances on VSD
        rt_names = [utils.get_random_name() for _ in range(2)]
        rt_ids = [
            self.l3domain.create_child(
                vspk.NURedirectionTarget(name=rt_name,
                                         endPointType='L3'))[0].id
            for rt_name in rt_names
        ]

        # create port with the redirect target in the VSD managed subnet
        # and verify
        port_name = utils.get_random_name()
        rts_arg = '--nuage-redirect-target {}'.format(rt_names[0])
        cmd_create = ('port create -f json {rts_arg} '
                      '--network {network} {name}'.format(
                          rts_arg=rts_arg,
                          network=self.NETWORK_NAME,
                          name=port_name))
        cmd_output = json.loads(self.openstack(cmd_create))
        self.assertEqual(observed=cmd_output['nuage_redirect_targets'],
                         expected=rt_ids[0])

        # Set rt that is already set (nothing should change)
        cmd_set = 'port set --nuage-redirect-target {rt_name} {port}'.format(
            rt_name=rt_names[0], port=port_name)
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(expected=rt_ids[0],
                         observed=cmd_output['nuage_redirect_targets'])

        # Unset and verify
        cmd_no_rts = ('port unset --nuage-redirect-target {port}'.format(
            port=port_name))
        cmd_output = self.openstack(cmd_no_rts)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertIsNone(cmd_output['nuage_redirect_targets'])

        # Overwrite and verify
        cmd_set = ('port set --nuage-redirect-target {} {}'.format(
            rt_ids[1], port_name))
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(expected=rt_ids[1],
                         observed=cmd_output['nuage_redirect_targets'])

        # delete and verify
        utils.delete_and_verify(self, 'port', port_name)
Example #3
0
    def test_vsd_managed_crud(self):
        session = create_new_vspk_session()
        enterprise = session.user.enterprises.get_first(
            filter='name == "{}"'.format(get_vsd_net_parition_name()))

        subnet_name = get_random_name()
        ip_config = get_random_ipv4_subnet_config()
        l2domain = create_l2_domain(self, enterprise, ip_config['address'],
                                    ip_config['netmask'], ip_config['gateway'])

        # CREATE / READ
        cmd_create = ('subnet create -f json --network {network} '
                      '--net-partition {net_partition} --nuagenet {nuagenet} '
                      '--subnet-range {subnet_range} {subnet_name} '
                      '--gateway None'
                      .format(network=self.NETWORK_NAME,
                              net_partition=enterprise.id,
                              nuagenet=l2domain.id,
                              subnet_range=ip_config['cidr'],
                              subnet_name=subnet_name))
        cmd_show = 'subnet show -f json {}'.format(subnet_name)
        for cmd in [cmd_create, cmd_show]:
            cmd_output = json.loads(self.openstack(cmd))
            self.assertEqual(expected=True,
                             observed=cmd_output['vsd_managed'])
            self.assertEqual(expected=subnet_name,
                             observed=cmd_output['name'])
            self.assertEqual(expected=l2domain.id,
                             observed=cmd_output['nuagenet'])
            self.assertEqual(expected=enterprise.id,
                             observed=cmd_output['net_partition'])
            self.assertEqual(expected=ip_config['cidr'],
                             observed=cmd_output['cidr'])

        # UPDATE
        update_cmd = 'subnet set --nuage-underlay route {}'.format(subnet_name)
        try:
            self.openstack(update_cmd)
        except exceptions.CommandFailed as e:
            self.assertIn(needle='is a VSD-managed subnet. Update is not '
                                 'supported for attributes other than ',
                          haystack=str(e.stderr))
        else:
            self.assertIsNotNone(None, message="Update command should fail.")

        # DELETE
        delete_and_verify(self, 'subnet', subnet_name)
    def test_port_no_vport(self):
        port_name = utils.get_random_name()
        cmd_create = ('port create -f json --vnic-type=direct '
                      '--network {network} {name}'.format(
                          network=self.NETWORK_NAME, name=port_name))
        cmd_output = json.loads(self.openstack(cmd_create))
        self.assertEqual(expected='direct',
                         observed=cmd_output['binding_vnic_type'])

        new_port_name = utils.get_random_name()
        cmd_update = ('port set --name {} {}'.format(new_port_name, port_name))
        cmd_output = self.openstack(cmd_update)
        self.assertEqual(expected='', observed=cmd_output)

        cmd_output = self._port_show(new_port_name)
        self.assertEqual(expected='direct',
                         observed=cmd_output['binding_vnic_type'])
        self.assertEqual(expected=new_port_name, observed=cmd_output['name'])

        # delete and verify
        utils.delete_and_verify(self, 'port', new_port_name)
    def test_nuage_floating_ip_option(self):
        """Create, delete a port with a nuage floating ip"""

        # Create Nuage floating ip
        shared_subnet = self._create_shared_fip_subnet(self.session, '1.1.1.0',
                                                       '255.255.255.0')
        floating_ip_str = '1.1.1.10'
        floating_ip = self.l3domain.create_child(
            vspk.NUFloatingIp(
                associated_shared_network_resource_id=shared_subnet.id,
                address=floating_ip_str))[0]
        self.addCleanup(floating_ip.delete)

        # Create a port with the Nuage floating ip in the VSD managed subnet
        port_name = utils.get_random_name()
        cmd_create = ('port create -f json --nuage-floatingip {floating_ip} '
                      '--network {network} {name}'.format(
                          floating_ip=floating_ip_str,
                          network=self.NETWORK_NAME,
                          name=port_name))
        cmd_output = json.loads(self.openstack(cmd_create))
        self.addCleanup(self.openstack, 'port delete {}'.format(port_name))

        # Verify create
        self.assertIsNotNone(cmd_output.get('nuage_floatingip'))
        self.assertEqual(observed=cmd_output['nuage_floatingip'],
                         expected=osc_utils.format_dict({
                             'id':
                             floating_ip.id,
                             'floating_ip_address':
                             floating_ip_str
                         }))

        # Verify show
        cmd_output = self._port_show(port_name)
        self.assertEqual(observed=cmd_output['nuage_floatingip'],
                         expected=osc_utils.format_dict({
                             'id':
                             floating_ip.id,
                             'floating_ip_address':
                             floating_ip_str
                         }))

        # Try to create again, expect failure
        cmd_create = ('port create -f json --nuage-floatingip {floating_ip} '
                      '--network {network} {name}'.format(
                          floating_ip=floating_ip_str,
                          network=self.NETWORK_NAME,
                          name=utils.get_random_name()))
        self.assertRaisesRegex(Exception, "Floating IP .* is already in use",
                               self.openstack, cmd_create)

        # Verify set / unset
        cmd_set = 'port set --nuage-floatingip 1.1.1.99 {}'.format(port_name)
        self.assertRaisesRegex(
            Exception, 'No Nuage Floating IP available with'
            ' IP 1.1.1.99', self.openstack, cmd_set)

        port_name_2 = utils.get_random_name()
        self.openstack('port create -f json --network {network} {name}'.format(
            network=self.NETWORK_NAME, name=port_name_2))

        cmd_set = 'port set --nuage-floatingip {} {}'.format(
            floating_ip_str, port_name_2)
        self.assertRaisesRegex(
            Exception,
            'Floating IP {} is already in use'.format(floating_ip_str),
            self.openstack, cmd_set)

        cmd_unset = 'port unset --nuage-floatingip {}'.format(port_name)
        self.openstack(cmd_unset)

        # Verify show (No Nuage floating ip)
        cmd_output = self._port_show(port_name)
        self.assertIsNone(cmd_output['nuage_floatingip'])

        # the set should work now, since we unsetted the previous fip
        self.openstack(cmd_set)

        # Verify delete
        utils.delete_and_verify(self, 'port', port_name_2)
    def test_nuage_policygroup_option(self):
        # create policygroups
        pg_names = [utils.get_random_name() for _ in range(2)]
        pg_ids = [
            self.l3domain.create_child(
                vspk.NUPolicyGroup(name=pg_name, type='SOFTWARE'))[0].id
            for pg_name in pg_names
        ]

        # create port with the policygroup in the VSD managed subnet and verify
        port_name = utils.get_random_name()
        pgs_arg = ' '.join('--nuage-policy-group {}'.format(name)
                           for name in pg_names)
        cmd_create = ('port create -f json {pgs_arg} '
                      '--network {network} {name}'.format(
                          pgs_arg=pgs_arg,
                          network=self.NETWORK_NAME,
                          name=port_name))
        cmd_output = json.loads(self.openstack(cmd_create))
        self.assertEqual(observed=cmd_output['nuage_policy_groups'],
                         expected=osc_utils.format_list(pg_ids))

        # Set pg that is already set (nothing should change)
        chosen_pg_id = random.choice(pg_ids)
        cmd_set = 'port set --nuage-policy-group {pg_id} {port}'.format(
            pg_id=chosen_pg_id, port=port_name)
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(expected=osc_utils.format_list(pg_ids),
                         observed=cmd_output['nuage_policy_groups'])

        # Unset all and verify
        cmd_no_pgs = 'port set --no-nuage-policy-groups {}'.format(port_name)
        cmd_output = self.openstack(cmd_no_pgs)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertIsNone(cmd_output['nuage_policy_groups'])

        # set all and verify
        cmd_set_all = 'port set {pgs_arg} {name}'.format(pgs_arg=pgs_arg,
                                                         name=port_name)
        cmd_output = self.openstack(cmd_set_all)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(expected=osc_utils.format_list(pg_ids),
                         observed=cmd_output['nuage_policy_groups'])

        # unset one and verify
        cmd_unset = ('port unset --nuage-policy-group {pg} {port}'.format(
            pg=chosen_pg_id, port=port_name))
        cmd_output = self.openstack(cmd_unset)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(observed=cmd_output['nuage_policy_groups'],
                         expected=osc_utils.format_list(
                             filter(lambda i: i != chosen_pg_id, pg_ids)))

        # overwrite and verify
        cmd_set = ('port set --no-nuage-policy-groups '
                   '--nuage-policy-group {} {}'.format(chosen_pg_id,
                                                       port_name))
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(expected=osc_utils.format_list([chosen_pg_id]),
                         observed=cmd_output['nuage_policy_groups'])

        # set one and verify
        pg_to_set = next(pg_id for pg_id in pg_ids if pg_id != chosen_pg_id)
        cmd_set = ('port set --nuage-policy-group {pg} {port}'.format(
            pg=pg_to_set, port=port_name))
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)
        cmd_output = self._port_show(port_name)
        self.assertEqual(expected=osc_utils.format_list(
            [chosen_pg_id, pg_to_set]),
                         observed=cmd_output['nuage_policy_groups'])

        # delete and verify
        utils.delete_and_verify(self, 'port', port_name)
    def test_nuage_options(self):
        # TODO(glenn) Test nuage-net-partition when the resource is implemented

        # Create a router with Nuage arguments and verify using router show
        router_name = utils.get_random_name()
        args_for_create = {
            'nuage_router_template': self._create_l3_domain_template().id,
            'nuage_rd': self._random_target(),
            'nuage_rt': self._random_target(),
            'nuage_backhaul_vnid': 12345678,
            'nuage_backhaul_rd': self._random_target(),
            'nuage_backhaul_rt': self._random_target(),
            'nuage_tunnel_type': 'GRE',
            'nuage_ecmp_count': 3,
            'nuage_underlay': 'snat'
        }

        cmd_create = ('router create -f json {args} {name}'.format(
            args=self._build_arg_str(args_for_create), name=router_name))
        cmd_show = 'router show -f json {}'.format(router_name)
        for cmd in [cmd_create, cmd_show]:
            cmd_output = json.loads(self.openstack(cmd))
            self._verify(expected=dict(args_for_create, name=router_name),
                         observed=cmd_output)

        # Set Nuage arguments and verify using router show
        # a. update a property and check that the other ones did not change
        args_for_set = {'nuage_ecmp_count': 4}
        cmd_set = ('router set {args} {router}'.format(
            args=self._build_arg_str(args_for_set), router=router_name))
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)

        cmd_show = 'router show -f json {}'.format(router_name)
        cmd_output = json.loads(self.openstack(cmd_show))
        self._verify(expected=dict(args_for_create, **args_for_set),
                     observed=cmd_output)

        # b. update all properties
        args_for_set = {
            'nuage_rd': self._random_target(),
            'nuage_rt': self._random_target(),
            'nuage_backhaul_vnid': 16777215,
            'nuage_backhaul_rd': self._random_target(),
            'nuage_backhaul_rt': self._random_target(),
            'nuage_tunnel_type': 'VXLAN',
            'nuage_ecmp_count': 4,
            'nuage_underlay': 'route',
            'name': utils.get_random_name()
        }

        cmd_set = ('router set {args} {router}'.format(
            args=self._build_arg_str(args_for_set), router=router_name))
        cmd_output = self.openstack(cmd_set)
        self.assertEqual(expected='', observed=cmd_output)

        cmd_show = 'router show -f json {}'.format(args_for_set['name'])
        cmd_output = json.loads(self.openstack(cmd_show))
        self._verify(expected=args_for_set, observed=cmd_output)

        # Delete the router and verify using router list
        utils.delete_and_verify(self, 'router', args_for_set['name'])