示例#1
0
    def test_crud(self):
        block = factory.create_block(cidr="77.1.1.0/24",
                                      tenant_id=self.tenant_id)
        create_res = self.command("ip_route create",
                                  ip_block_id=block['id'],
                                  destination="10.1.1.2",
                                  gateway="10.1.1.1",
                                  netmask="255.255.255.0")
        route = factory.model("ip_route", create_res)
        self.assertShows("ip_route",
                          route,
                          parameters="ip_block_id=%s id=%s" % (block['id'],
                                                               route['id']))

        another_create_res = self.command("ip_route create",
                                          ip_block_id=block['id'],
                                          destination="20.1.1.2",
                                          gateway="20.1.1.1",
                                          netmask="255.255.255.0")
        another_route = factory.model("ip_route", another_create_res)

        list_res = self.command("ip_route list",
                                ip_block_id=block['id'])
        self.assertTableEquals([route, another_route], list_res['out'])

        self.command("ip_route delete",
                     ip_block_id=block['id'],
                     id=route['id'])

        self.assertResourceNotFound("ip_route",
                                    route,
                                    parameters="ip_block_id=%s id=%s"
                                    % (block['id'], route['id']))
示例#2
0
    def test_crud(self):
        block = factory.create_block(cidr="77.1.1.0/24",
                                     tenant_id=self.tenant_id)
        create_res = self.command("ip_route create",
                                  ip_block_id=block['id'],
                                  destination="10.1.1.2",
                                  gateway="10.1.1.1",
                                  netmask="255.255.255.0")
        route = factory.model("ip_route", create_res)
        self.assertShows("ip_route",
                         route,
                         parameters="ip_block_id=%s id=%s" %
                         (block['id'], route['id']))

        another_create_res = self.command("ip_route create",
                                          ip_block_id=block['id'],
                                          destination="20.1.1.2",
                                          gateway="20.1.1.1",
                                          netmask="255.255.255.0")
        another_route = factory.model("ip_route", another_create_res)

        list_res = self.command("ip_route list", ip_block_id=block['id'])
        self.assertTableEquals([route, another_route], list_res['out'])

        self.command("ip_route delete",
                     ip_block_id=block['id'],
                     id=route['id'])

        self.assertResourceNotFound("ip_route",
                                    route,
                                    parameters="ip_block_id=%s id=%s" %
                                    (block['id'], route['id']))
示例#3
0
    def test_create(self):
        policy = factory.create_policy(tenant_id=self.tenant_id)

        create_res = self.command('unusable_ip_range create',
                                  policy_id=policy['id'],
                                  offset=1,
                                  length=2)

        ip_range = factory.model('ip_range', create_res)
        self.assertShows('ip_range',
                          ip_range,
                          command_name="unusable_ip_range",
                          parameters="id=%s policy_id=%s" % (ip_range['id'],
                                                             policy['id']))
        update_res = self.command('unusable_ip_range update',
                                  policy_id=policy['id'],
                                  id=ip_range['id'],
                                  offset=10,
                                  length=122)
        updated_ip_range = factory.model('ip_range', update_res)
        self.assertShows('ip_range',
                         updated_ip_range,
                         command_name="unusable_ip_range",
                        parameters="id=%s policy_id=%s" % (ip_range['id'],
                                                           policy['id']))

        another_create_res = self.command('unusable_ip_range create',
                                          policy_id=policy['id'],
                                          offset=1,
                                          length=2)

        another_ip_range = factory.model('ip_range', another_create_res)

        list_res = functional.run("unusable_ip_range list"
                       " policy_id={0} -t {1}".format(policy['id'],
                           self.tenant_id))

        self.assertEqual(sorted([updated_ip_range, another_ip_range]),
                         sorted(yaml.load(list_res['out'])['ip_ranges']))

        self.command("unusable_ip_range delete",
                     policy_id=policy['id'],
                     id=ip_range['id'])

        parameters = ("policy_id=%s id=%s" % (policy['id'],
                                              ip_range['id']))
        self.assertResourceNotFound("ip_range",
                                    ip_range,
                                    command_name="unusable_ip_range",
                                    parameters=parameters)
示例#4
0
    def test_create(self):
        policy = factory.create_policy(tenant_id=self.tenant_id)

        create_res = self.command('unusable_ip_range create',
                                  policy_id=policy['id'],
                                  offset=1,
                                  length=2)

        ip_range = factory.model('ip_range', create_res)
        self.assertShows('ip_range',
                         ip_range,
                         command_name="unusable_ip_range",
                         parameters="id=%s policy_id=%s" %
                         (ip_range['id'], policy['id']))
        update_res = self.command('unusable_ip_range update',
                                  policy_id=policy['id'],
                                  id=ip_range['id'],
                                  offset=10,
                                  length=122)
        updated_ip_range = factory.model('ip_range', update_res)
        self.assertShows('ip_range',
                         updated_ip_range,
                         command_name="unusable_ip_range",
                         parameters="id=%s policy_id=%s" %
                         (ip_range['id'], policy['id']))

        another_create_res = self.command('unusable_ip_range create',
                                          policy_id=policy['id'],
                                          offset=1,
                                          length=2)

        another_ip_range = factory.model('ip_range', another_create_res)

        list_res = functional.run("unusable_ip_range list"
                                  " policy_id={0} -t {1}".format(
                                      policy['id'], self.tenant_id))

        self.assertEqual(sorted([updated_ip_range, another_ip_range]),
                         sorted(yaml.load(list_res['out'])['ip_ranges']))

        self.command("unusable_ip_range delete",
                     policy_id=policy['id'],
                     id=ip_range['id'])

        parameters = ("policy_id=%s id=%s" % (policy['id'], ip_range['id']))
        self.assertResourceNotFound("ip_range",
                                    ip_range,
                                    command_name="unusable_ip_range",
                                    parameters=parameters)
示例#5
0
    def test_crud(self):
        network_id = uuid.uuid4()
        iface = factory.create_interface(network_id=network_id,
                                          tenant_id=self.tenant_id)
        block = factory.create_block(cidr="20.1.1.0/24",
                                      network_id=network_id,
                                      tenant_id=self.tenant_id)
        ip = factory.create_ip(address="20.1.1.2",
                                block_id=block['id'],
                                used_by_tenant=self.tenant_id,
                                tenant_id=self.tenant_id)
        another_ip = factory.create_ip(address="20.1.1.3",
                                        block_id=block['id'],
                                        used_by_tenant=self.tenant_id,
                                        tenant_id=self.tenant_id)

        ip_res = self.command("allowed_ip create",
                              interface_id=iface['id'],
                              network_id=network_id,
                              ip_address=ip['address'])
        allowed_ip = factory.model("ip_address", ip_res)
        self.assertShows("ip_address",
                         allowed_ip,
                         parameters="interface_id=%s ip_address=%s" %
                                    (iface['id'], ip['address']),
                         command_name="allowed_ip")

        another_ip_res = self.command("allowed_ip create",
                                      interface_id=iface['id'],
                                      network_id=network_id,
                                      ip_address=another_ip['address'])

        another_allowed_ip = factory.model('ip_address', another_ip_res)

        list_res = self.command("allowed_ip list", interface_id=iface['id'])
        actual_allowed_ips = yaml.load(list_res['out'])['ip_addresses']
        self.assertTrue(allowed_ip in actual_allowed_ips)
        self.assertTrue(another_allowed_ip in actual_allowed_ips)

        self.command("allowed_ip delete",
                     interface_id=iface['id'],
                     ip_address=ip['address'])
        show_res = self.command("allowed_ip show",
                                interface_id=iface['id'],
                                ip_address=ip['address'],
                                raise_error=False)
        expected_error = ("Ip Address %s hasnt been allowed on interface %s" %
                          (ip['address'], iface['id']))
        self.assertTrue(expected_error in show_res['out'])
示例#6
0
    def test_crud(self):
        network_id = uuid.uuid4()
        iface = factory.create_interface(network_id=network_id,
                                         tenant_id=self.tenant_id)
        block = factory.create_block(cidr="20.1.1.0/24",
                                     network_id=network_id,
                                     tenant_id=self.tenant_id)
        ip = factory.create_ip(address="20.1.1.2",
                               block_id=block['id'],
                               used_by_tenant=self.tenant_id,
                               tenant_id=self.tenant_id)
        another_ip = factory.create_ip(address="20.1.1.3",
                                       block_id=block['id'],
                                       used_by_tenant=self.tenant_id,
                                       tenant_id=self.tenant_id)

        ip_res = self.command("allowed_ip create",
                              interface_id=iface['id'],
                              network_id=network_id,
                              ip_address=ip['address'])
        allowed_ip = factory.model("ip_address", ip_res)
        self.assertShows("ip_address",
                         allowed_ip,
                         parameters="interface_id=%s ip_address=%s" %
                         (iface['id'], ip['address']),
                         command_name="allowed_ip")

        another_ip_res = self.command("allowed_ip create",
                                      interface_id=iface['id'],
                                      network_id=network_id,
                                      ip_address=another_ip['address'])

        another_allowed_ip = factory.model('ip_address', another_ip_res)

        list_res = self.command("allowed_ip list", interface_id=iface['id'])
        actual_allowed_ips = yaml.load(list_res['out'])['ip_addresses']
        self.assertTrue(allowed_ip in actual_allowed_ips)
        self.assertTrue(another_allowed_ip in actual_allowed_ips)

        self.command("allowed_ip delete",
                     interface_id=iface['id'],
                     ip_address=ip['address'])
        show_res = self.command("allowed_ip show",
                                interface_id=iface['id'],
                                ip_address=ip['address'],
                                raise_error=False)
        expected_error = ("Ip Address %s hasnt been allowed on interface %s" %
                          (ip['address'], iface['id']))
        self.assertTrue(expected_error in show_res['out'])
示例#7
0
    def test_create_and_list(self):
        block = factory.create_block(cidr="10.0.0.0/8", tenant_id="123")
        subnet_res_1 = functional.run("subnet create parent_id={0} "
                         "cidr=10.0.1.0/29 -t 123".format(block['id']))
        self.assertEqual(0, subnet_res_1['exitcode'])

        subnet_res_2 = functional.run("subnet create parent_id={0} "
                         "cidr=10.0.0.0/29 -t 123".format(block['id']))
        self.assertEqual(0, subnet_res_2['exitcode'])

        subnet_list_res = functional.run("subnet list parent_id={0} "
                              "-t 123".format(block['id']))
        self.assertEqual(sorted([factory.model('subnet', subnet_res_1),
                                 factory.model('subnet', subnet_res_2)]),
                         sorted(factory.model('subnets', subnet_list_res)))
示例#8
0
    def test_list(self):
        block1 = factory.create_block(self.tenant_id)
        block2 = factory.create_block(self.tenant_id)
        list_res = functional.run("ip_block list -t %s" % self.tenant_id)

        self.assertEqual(0, list_res['exitcode'])
        self.assertEqual(sorted([block1, block2]),
                         sorted(factory.model('ip_blocks', list_res)))
示例#9
0
    def test_list(self):
        block1 = factory.create_block(self.tenant_id)
        block2 = factory.create_block(self.tenant_id)
        list_res = functional.run("ip_block list -t %s" % self.tenant_id)

        self.assertEqual(0, list_res['exitcode'])
        self.assertEqual(sorted([block1, block2]),
                         sorted(factory.model('ip_blocks', list_res)))
示例#10
0
    def test_crud(self):
        policy = factory.create_policy(tenant_id=self.tenant_id)

        create_res = self.command('unusable_ip_octet create',
                                  policy_id=policy['id'],
                                  octet=255)
        ip_octet = factory.model('ip_octet', create_res)
        self.assertShows('ip_octet',
                         ip_octet,
                         command_name="unusable_ip_octet",
                         parameters="id=%s policy_id=%s" % (ip_octet['id'],
                                                            policy['id']))

        update_res = self.command('unusable_ip_octet update',
                                  policy_id=policy['id'],
                                  id=ip_octet['id'],
                                  octet=200)
        updated_ip_octet = factory.model('ip_octet', update_res)
        self.assertShows('ip_octet', updated_ip_octet,
                          command_name="unusable_ip_octet",
                          parameters="id=%s policy_id=%s" % (ip_octet['id'],
                                                             policy['id']))

        another_create_res = self.command('unusable_ip_octet create',
                                          policy_id=policy['id'],
                                          octet=200)
        another_ip_octet = factory.model('ip_octet', another_create_res)

        list_res = functional.run("unusable_ip_octet list policy_id={0}"
                                  " -t {1}".format(policy['id'],
                                                   self.tenant_id))

        self.assertEqual(sorted([updated_ip_octet, another_ip_octet]),
                         sorted(yaml.load(list_res['out'])['ip_octets']))

        self.command("unusable_ip_octet delete",
                     policy_id=policy['id'],
                     id=ip_octet['id'])

        parameters = "policy_id=%s id=%s" % (policy['id'],
                                              ip_octet['id'])
        self.assertResourceNotFound("ip_octet",
                                    ip_octet,
                                    command_name='unusable_ip_octet',
                                    parameters=parameters)
示例#11
0
    def test_crud(self):
        policy = factory.create_policy(tenant_id=self.tenant_id)

        create_res = self.command('unusable_ip_octet create',
                                  policy_id=policy['id'],
                                  octet=255)
        ip_octet = factory.model('ip_octet', create_res)
        self.assertShows('ip_octet',
                         ip_octet,
                         command_name="unusable_ip_octet",
                         parameters="id=%s policy_id=%s" %
                         (ip_octet['id'], policy['id']))

        update_res = self.command('unusable_ip_octet update',
                                  policy_id=policy['id'],
                                  id=ip_octet['id'],
                                  octet=200)
        updated_ip_octet = factory.model('ip_octet', update_res)
        self.assertShows('ip_octet',
                         updated_ip_octet,
                         command_name="unusable_ip_octet",
                         parameters="id=%s policy_id=%s" %
                         (ip_octet['id'], policy['id']))

        another_create_res = self.command('unusable_ip_octet create',
                                          policy_id=policy['id'],
                                          octet=200)
        another_ip_octet = factory.model('ip_octet', another_create_res)

        list_res = functional.run("unusable_ip_octet list policy_id={0}"
                                  " -t {1}".format(policy['id'],
                                                   self.tenant_id))

        self.assertEqual(sorted([updated_ip_octet, another_ip_octet]),
                         sorted(yaml.load(list_res['out'])['ip_octets']))

        self.command("unusable_ip_octet delete",
                     policy_id=policy['id'],
                     id=ip_octet['id'])

        parameters = "policy_id=%s id=%s" % (policy['id'], ip_octet['id'])
        self.assertResourceNotFound("ip_octet",
                                    ip_octet,
                                    command_name='unusable_ip_octet',
                                    parameters=parameters)
示例#12
0
 def _assert_ip_shows(self, expected_resource):
     show_command = ("ip_address show ip_block_id=%s address=%s "
                    "-t %s" % (expected_resource['ip_block_id'],
                               expected_resource['address'],
                               self.tenant_id))
     show_res = functional.run(show_command)
     shown_resource = factory.model('ip_address', show_res)
     for key, expected_resource_field in expected_resource.iteritems():
         self.assertEqual(expected_resource_field, shown_resource[key])
示例#13
0
 def _assert_ip_shows(self, expected_resource):
     show_command = ("ip_address show ip_block_id=%s address=%s "
                     "-t %s" %
                     (expected_resource['ip_block_id'],
                      expected_resource['address'], self.tenant_id))
     show_res = functional.run(show_command)
     shown_resource = factory.model('ip_address', show_res)
     for key, expected_resource_field in expected_resource.iteritems():
         self.assertEqual(expected_resource_field, shown_resource[key])
示例#14
0
    def test_crud(self):
        create_res = self.command("policy create",
                                  name="policy_name",
                                  desc="policy_desc")
        self.assertEqual(0, create_res['exitcode'])
        policy = factory.model('policy', create_res)
        self.assertShows('policy', policy)

        update_res = self.command("policy update",
                                  id=policy['id'],
                                  name="new_name")
        self.assertEqual(0, update_res['exitcode'])
        updated_policy = factory.model('policy', update_res)
        self.assertShows('policy', updated_policy)

        delete_res = self.command("policy delete", id=policy['id'])
        self.assertEqual(0, delete_res['exitcode'])

        self.assertResourceNotFound('policy', policy)
示例#15
0
    def test_crud(self):
        create_res = self.command("policy create",
                                  name="policy_name",
                                  desc="policy_desc")
        self.assertEqual(0, create_res['exitcode'])
        policy = factory.model('policy', create_res)
        self.assertShows('policy', policy)

        update_res = self.command("policy update",
                                  id=policy['id'],
                                  name="new_name")
        self.assertEqual(0, update_res['exitcode'])
        updated_policy = factory.model('policy', update_res)
        self.assertShows('policy', updated_policy)

        delete_res = self.command("policy delete", id=policy['id'])
        self.assertEqual(0, delete_res['exitcode'])

        self.assertResourceNotFound('policy', policy)
示例#16
0
    def test_create_and_list(self):
        block = factory.create_block(cidr="10.0.0.0/8", tenant_id="123")
        subnet_res_1 = functional.run("subnet create parent_id={0} "
                                      "cidr=10.0.1.0/29 -t 123".format(
                                          block['id']))
        self.assertEqual(0, subnet_res_1['exitcode'])

        subnet_res_2 = functional.run("subnet create parent_id={0} "
                                      "cidr=10.0.0.0/29 -t 123".format(
                                          block['id']))
        self.assertEqual(0, subnet_res_2['exitcode'])

        subnet_list_res = functional.run("subnet list parent_id={0} "
                                         "-t 123".format(block['id']))
        self.assertEqual(
            sorted([
                factory.model('subnet', subnet_res_1),
                factory.model('subnet', subnet_res_2)
            ]), sorted(factory.model('subnets', subnet_list_res)))
示例#17
0
    def test_crud(self):
        create_res = functional.run("ip_block create type=private "
                                    "cidr=10.1.1.0/29 network_id=%s "
                                    "-t %s" % (uuid.uuid4(), self.tenant_id))
        ip_block = factory.model('ip_block', create_res)
        self.assertEqual(0, create_res['exitcode'])
        self.assertShows('ip_block', ip_block)

        update_res = functional.run(
            "ip_block update id=%s network_id=%s "
            "-t %s" % (ip_block['id'], uuid.uuid4(), self.tenant_id))
        updated_block = factory.model('ip_block', update_res)
        self.assertEqual(0, update_res['exitcode'])
        self.assertShows('ip_block', updated_block)

        deleted_res = functional.run("ip_block delete "
                                     "id=%s -t %s" %
                                     (ip_block['id'], self.tenant_id))
        self.assertEqual(0, deleted_res['exitcode'])
        self.assertResourceNotFound('ip_block', ip_block)
示例#18
0
    def test_crud(self):
        create_res = functional.run("ip_block create type=private "
                                    "cidr=10.1.1.0/29 network_id=%s "
                                    "-t %s" % (uuid.uuid4(), self.tenant_id))
        ip_block = factory.model('ip_block', create_res)
        self.assertEqual(0, create_res['exitcode'])
        self.assertShows('ip_block', ip_block)

        update_res = functional.run("ip_block update id=%s network_id=%s "
                                    "-t %s" % (ip_block['id'],
                                               uuid.uuid4(),
                                               self.tenant_id))
        updated_block = factory.model('ip_block', update_res)
        self.assertEqual(0, update_res['exitcode'])
        self.assertShows('ip_block', updated_block)

        deleted_res = functional.run("ip_block delete "
                                     "id=%s -t %s" % (ip_block['id'],
                                                      self.tenant_id))
        self.assertEqual(0, deleted_res['exitcode'])
        self.assertResourceNotFound('ip_block', ip_block)
示例#19
0
    def assertShows(self, res_name, expected_resource, is_tenanted=True,
                    command_name=None, parameters=""):
        command_name = command_name or res_name
        parameters = parameters or "id=%s" % expected_resource['id']
        tenant_option = "-t %s" % self.tenant_id if is_tenanted else ""

        show_command = ("%s show %s %s"
                       % (command_name, parameters, tenant_option))
        show_res = functional.run(show_command)

        shown_resource = factory.model(res_name, show_res)
        for key, expected_resource_field in expected_resource.iteritems():
            self.assertEqual(expected_resource_field, shown_resource[key])
示例#20
0
    def test_crud(self):
        create_res = self.command("mac_address_range create",
                                  is_tenanted=False,
                                  cidr="ab-bc-cd-12-23-34/2")
        rng = factory.model('mac_address_range', create_res)
        self.assertShows('mac_address_range', rng, is_tenanted=False)
        another_create_res = self.command("mac_address_range create",
                                          is_tenanted=False,
                                          cidr="bc-ab-dc-12-23-34/2")
        another_rng = factory.model('mac_address_range', another_create_res)

        list_res = self.command("mac_address_range list", is_tenanted=False)
        rng_list = yaml.load(list_res['out'])['mac_address_ranges']
        self.assertTrue(rng in rng_list)
        self.assertTrue(another_rng in rng_list)

        self.command("mac_address_range delete",
                     is_tenanted=False,
                     id=rng['id'])
        self.assertResourceNotFound('mac_address_range',
                                    rng,
                                    is_tenanted=False)
示例#21
0
    def test_crud(self):
        create_res = self.command("mac_address_range create",
                                  is_tenanted=False,
                                  cidr="ab-bc-cd-12-23-34/2")
        rng = factory.model('mac_address_range', create_res)
        self.assertShows('mac_address_range', rng, is_tenanted=False)
        another_create_res = self.command("mac_address_range create",
                                          is_tenanted=False,
                                          cidr="bc-ab-dc-12-23-34/2")
        another_rng = factory.model('mac_address_range', another_create_res)

        list_res = self.command("mac_address_range list", is_tenanted=False)
        rng_list = yaml.load(list_res['out'])['mac_address_ranges']
        self.assertTrue(rng in rng_list)
        self.assertTrue(another_rng in rng_list)

        self.command("mac_address_range delete",
                     is_tenanted=False,
                     id=rng['id'])
        self.assertResourceNotFound('mac_address_range',
                                    rng,
                                    is_tenanted=False)
示例#22
0
    def assertShows(self,
                    res_name,
                    expected_resource,
                    is_tenanted=True,
                    command_name=None,
                    parameters=""):
        command_name = command_name or res_name
        parameters = parameters or "id=%s" % expected_resource['id']
        tenant_option = "-t %s" % self.tenant_id if is_tenanted else ""

        show_command = ("%s show %s %s" %
                        (command_name, parameters, tenant_option))
        show_res = functional.run(show_command)

        shown_resource = factory.model(res_name, show_res)
        for key, expected_resource_field in expected_resource.iteritems():
            self.assertEqual(expected_resource_field, shown_resource[key])