def command(self, command_name, is_tenanted=True, raise_error=True,
             **kwargs):
     parameters = ["%s=%s" % (key, value)
                  for key, value in kwargs.iteritems()]
     cmd_args = " ".join(parameters)
     if is_tenanted:
         return functional.run("{0} -t {1} {2} ".format(command_name,
                                             self.tenant_id,
                                             cmd_args),
                                             raise_error=raise_error)
     else:
         return functional.run("{0} {1} ".format(command_name, cmd_args),
                               raise_error=raise_error)
    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)))
    def test_list_with_tenant(self):
        device1_id, device2_id = uuid.uuid4(), uuid.uuid4()
        tenant1_id, tenant2_id = uuid.uuid4(), uuid.uuid4()
        block = factory.create_block(cidr="30.1.1.1/24",
                                      tenant_id=self.tenant_id)
        tenant1_ip1 = factory.create_ip(block_id=block['id'],
                                         address="30.1.1.2",
                                         used_by_device=device1_id,
                                         tenant_id=self.tenant_id,
                                         used_by_tenant=tenant1_id,)
        tenant1_ip2 = factory.create_ip(block_id=block['id'],
                                         address="30.1.1.3",
                                         used_by_device=device1_id,
                                         tenant_id=self.tenant_id,
                                         used_by_tenant=tenant1_id,)
        tenant2_ip1 = factory.create_ip(block_id=block['id'],
                                         address="30.1.1.4",
                                         used_by_device=device2_id,
                                         tenant_id=self.tenant_id,
                                         used_by_tenant=tenant2_id)

        list_res = functional.run("allocated_ip list -t %s" % tenant1_id)

        self.assertEqual(sorted([tenant1_ip1, tenant1_ip2]),
                         sorted(yaml.load(list_res['out'])['ip_addresses']))
    def test_list(self):
        policy1 = factory.create_policy(self.tenant_id)
        policy2 = factory.create_policy(self.tenant_id)
        list_res = functional.run("policy list -t %s" % self.tenant_id)

        self.assertEqual(sorted([policy1, policy2]),
                         sorted(yaml.load(list_res['out'])['policies']))
    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)))
 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])
Esempio n. 7
0
def create_interface(vif_id=None, device_id="device", network_id=None,
        tenant_id=None):
    vif_id = vif_id or uuid.uuid4()

    network_id = network_id or uuid.uuid4()
    tenant_id = tenant_id or uuid.uuid4()
    create_res = functional.run("interface create vif_id=%s tenant_id=%s "
                     "device_id=%s network_id=%s "
                     "network_tenant_id=%s" % (vif_id, tenant_id, device_id,
                                              network_id, tenant_id))
    return model("interface", create_res)
    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)
Esempio n. 9
0
def create_ip(address="10.1.1.1", used_by_tenant=None,
              used_by_device="device", interface_id=None,
              block_id=None, tenant_id=None):
    used_by_tenant = used_by_tenant or tenant_id
    interface_id = interface_id or uuid.uuid4()
    block_id = block_id or create_block(cidr="10.1.1.1/24",
                                        tenant_id=tenant_id)['id']
    create_res = functional.run("ip_address create ip_block_id=%s address=%s "
                "interface_id=%s used_by_tenant=%s "
                "used_by_device=%s -t %s " % (block_id, address, interface_id,
                                             used_by_tenant, used_by_device,
                                             tenant_id))
    return model("ip_address", create_res)
    def assertResourceNotFound(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_res = functional.run("%s show %s %s " % (command_name,
                                                      parameters,
                                                      tenant_option),
                                   raise_error=False)
        self.assertTrue("%s Not Found" % utils.camelize(res_name)
                        in show_res['out'])
    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])
    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)
    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)
Esempio n. 14
0
def create_policy(tenant_id="123"):
    create_res = functional.run("policy create name=policy_name "
                                "desc=policy_desc "
                                "-t %s" % tenant_id)
    return yaml.load(create_res['out'])['policy']
 def test_raises_error_for_non_keyword_arguments(self):
     res = functional.run("allowed_ip delete interface_id123 -t RAX",
                          raise_error=False)
     self.assertEqual(res['exitcode'], 2)
     self.assertIn("Action arguments should be of the form of field=value",
                   res['out'])
 def test_list_without_tenant_id_should_error_out(self):
     err_res = functional.run("ip_block list")
     self.assertTrue(0 != err_res['exitcode'])
Esempio n. 17
0
def create_block(tenant_id="1234", cidr="10.1.1.0/29", network_id=None):
    network_id = network_id or uuid.uuid4()
    create_res = functional.run("ip_block create type=private "
                     "cidr=%(cidr)s network_id=%(network_id)s "
                     "-t %(tenant_id)s" % locals())
    return model('ip_block', create_res)
Esempio n. 18
0
 def test_raises_error_if_no_tenant_id_specified(self):
     res = functional.run("tenant_allocated_ip list")
     self.assertTrue("Please provide a tenant id" in res['out'])