Exemplo n.º 1
0
 def create_and_update_policy_rule(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(
         prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name,
                                    classifier_args['protocol'],
                                    classifier_args['port_range'],
                                    classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(
         prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
     # Now create a new action and classifier and update
     action_name1 = rutils.generate_random_name(
         prefix="rally_action_allow_")
     self._create_policy_action(name=action_name1)
     # Create a policy classifier
     classifier_name1 = rutils.generate_random_name(
         prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name1,
                                    classifier_args['protocol'],
                                    classifier_args['port_range'],
                                    classifier_args['direction'])
     self._update_policy_rule(rule_name, action_name1, classifier_name1)
Exemplo n.º 2
0
 def create_and_update_policy_action(self, action_type="allow"):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name, type=action_type)
     # Create a new action name and update
     action_name1 = rutils.generate_random_name(
         prefix="rally_action_allow_")
     self._update_policy_action(name=action_name, new_name=action_name1)
Exemplo n.º 3
0
 def create_and_delete_policy_target_group(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(
         prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name,
                                    classifier_args['protocol'],
                                    classifier_args['port_range'],
                                    classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(
         prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
     # Now create a policy rule set
     ruleset_name = rutils.generate_random_name(prefix="rally_ruleset_web_")
     self._create_policy_rule_set(ruleset_name, [rule_name])
     # Now create a policy target group
     pt_group_name = rutils.generate_random_name(prefix="rally_group_")
     self._create_policy_target_group(pt_group_name)
     self._delete_policy_target_group(pt_group_name)
     self._delete_policy_rule_set(ruleset_name)
     self._delete_policy_rule(rule_name)
     self._delete_policy_classifier(classifier_name)
     self._delete_policy_action(name=action_name)
Exemplo n.º 4
0
 def create_and_delete_policy_classifier(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     classifier_name = rutils.generate_random_name(prefix="rally_classifier_")
     self._create_policy_classifier(classifier_name, classifier_args['protocol'], classifier_args['port_range'],
                                   classifier_args['direction'])
     self._delete_policy_classifier(classifier_name)
     self._delete_policy_action(name=action_name)
Exemplo n.º 5
0
 def create_policy_classifier(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     classifier_name = rutils.generate_random_name(
         prefix="rally_classifier_")
     self._create_policy_classifier(classifier_name,
                                    classifier_args['protocol'],
                                    classifier_args['port_range'],
                                    classifier_args['direction'])
Exemplo n.º 6
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        The following keyword arguments are accepted:

        * add_router: Create an external router and add an interface to each
                      subnet created. Default: False
        * subnets_num: Number of subnets to create per network. Default: 0
        * dns_nameservers: Nameservers for each subnet. Default:
                           8.8.8.8, 8.8.4.4
        * network_create_args: Additional network creation arguments.

        :param tenant_id: str, tenant ID
        :param kwargs: Additional options, left open-ended for compatbilitiy.
                       See above for recognized keyword args.
        :returns: dict, network data
        """
        network_args = {"network": kwargs.get("network_create_args", {})}
        network_args["network"].update({
            "tenant_id": tenant_id,
            "name": utils.generate_random_name("rally_net_")
        })
        network = self.client.create_network(network_args)["network"]

        router = None
        if kwargs.get("add_router", False):
            router = self.create_router(external=True, tenant_id=tenant_id)

        subnets = []
        subnets_num = kwargs.get("subnets_num", 0)
        for i in range(subnets_num):
            subnet_args = {
                "subnet": {
                    "tenant_id": tenant_id,
                    "network_id": network["id"],
                    "name": utils.generate_random_name("rally_subnet_"),
                    "ip_version": self.SUBNET_IP_VERSION,
                    "cidr": self._generate_cidr(),
                    "enable_dhcp": True,
                    "dns_nameservers": kwargs.get("dns_nameservers",
                                                  ["8.8.8.8", "8.8.4.4"])
                }
            }
            subnet = self.client.create_subnet(subnet_args)["subnet"]
            subnets.append(subnet["id"])

            if router:
                self.client.add_interface_router(router["id"],
                                                 {"subnet_id": subnet["id"]})

        return {"id": network["id"],
                "name": network["name"],
                "status": network["status"],
                "subnets": subnets,
                "external": network.get("router:external", False),
                "router_id": router and router["id"] or None,
                "tenant_id": tenant_id}
Exemplo n.º 7
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: extra options
        :returns: dict, network data
        """
        network_args = {
            "network": {
                "tenant_id": tenant_id,
                "name": utils.generate_random_name("rally_net_")
            }
        }
        network = self.client.create_network(network_args)["network"]

        router = None
        if kwargs.get("add_router", False):
            router = self.create_router(external=True, tenant_id=tenant_id)

        subnets = []
        subnets_num = kwargs.get("subnets_num", 0)
        for i in range(subnets_num):
            subnet_args = {
                "subnet": {
                    "tenant_id":
                    tenant_id,
                    "network_id":
                    network["id"],
                    "name":
                    utils.generate_random_name("rally_subnet_"),
                    "ip_version":
                    self.SUBNET_IP_VERSION,
                    "cidr":
                    self._generate_cidr(),
                    "enable_dhcp":
                    True,
                    "dns_nameservers":
                    kwargs.get("dns_nameservers", ["8.8.8.8", "8.8.4.4"])
                }
            }
            subnet = self.client.create_subnet(subnet_args)["subnet"]
            subnets.append(subnet["id"])

            if router:
                self.client.add_interface_router(router["id"],
                                                 {"subnet_id": subnet["id"]})

        return {
            "id": network["id"],
            "name": network["name"],
            "status": network["status"],
            "subnets": subnets,
            "external": network.get("router:external", False),
            "router_id": router and router["id"] or None,
            "tenant_id": tenant_id
        }
Exemplo n.º 8
0
 def create_policy_rule(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name,classifier_args['protocol'], classifier_args['port_range'],
                                    classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
Exemplo n.º 9
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: extra options
        :returns: dict, network data
        """
        network_args = {
            "network": {
                "tenant_id": tenant_id,
                "name": utils.generate_random_name("rally_net_")
            }
        }
        network = self.client.create_network(network_args)["network"]

        router = None
        if kwargs.get("add_router", False):
            router = self.create_router(external=True, tenant_id=tenant_id)

        subnets = []
        subnets_num = kwargs.get("subnets_num", 0)
        for i in range(subnets_num):
            subnet_args = {
                "subnet": {
                    "tenant_id": tenant_id,
                    "network_id": network["id"],
                    "name": utils.generate_random_name("rally_subnet_"),
                    "ip_version": self.SUBNET_IP_VERSION,
                    "cidr": self._generate_cidr(),
                    "enable_dhcp": True,
                    "dns_nameservers": kwargs.get("dns_nameservers",
                                                  ["8.8.8.8", "8.8.4.4"])
                }
            }
            subnet = self.client.create_subnet(subnet_args)["subnet"]
            subnets.append(subnet["id"])

            if router:
                self.client.add_interface_router(router["id"],
                                                 {"subnet_id": subnet["id"]})

        return {"id": network["id"],
                "name": network["name"],
                "status": network["status"],
                "subnets": subnets,
                "external": network.get("router:external", False),
                "router_id": router and router["id"] or None,
                "tenant_id": tenant_id}
Exemplo n.º 10
0
    def _change_app_fullname(self, app_dir):
        """Change application full name.

        To avoid name conflict error during package import (when user
        tries to import a few packages into the same tenant) need to change the
        application name. For doing this need to replace following parts
        in manifest.yaml
        from
            ...
            FullName: app.name
            ...
            Classes:
              app.name: app_class.yaml
        to:
            ...
            FullName: <new_name>
            ...
            Classes:
              <new_name>: app_class.yaml

        :param app_dir: path to directory with Murano application context
        """

        new_fullname = common_utils.generate_random_name("app.")

        manifest_file = os.path.join(app_dir, "manifest.yaml")
        manifest = self._read_from_file(manifest_file)

        class_file_name = manifest["Classes"][manifest["FullName"]]

        # update manifest.yaml file
        del manifest["Classes"][manifest["FullName"]]
        manifest["FullName"] = new_fullname
        manifest["Classes"][new_fullname] = class_file_name
        self._write_to_file(manifest, manifest_file)
    def setup(self):
        utils.init_sahara_context(self)
        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):

            clients = osclients.Clients(user["endpoint"])
            sahara = clients.sahara()

            if self.config["output_type"] == "swift":
                swift = swift_utils.SwiftScenario(clients=clients,
                                                  context=self.context)
                container_name = rutils.generate_random_name(
                    prefix=self.config["output_url_prefix"])
                self.context["tenants"][tenant_id]["sahara"]["container"] = {
                    "name": swift._create_container(
                        container_name=container_name),
                    "output_swift_objects": []
                }
                self.setup_outputs_swift(swift, sahara, tenant_id,
                                         container_name,
                                         user["endpoint"].username,
                                         user["endpoint"].password)
            else:
                self.setup_outputs_hdfs(sahara, tenant_id,
                                        self.config["output_url_prefix"])
Exemplo n.º 12
0
 def create_and_update_policy_target_group(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name, classifier_args['protocol'],
                                    classifier_args['port_range'], classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
     # Now create a policy rule set
     ruleset_name = rutils.generate_random_name(prefix="rally_ruleset_web_")
     self._create_policy_rule_set(ruleset_name, [rule_name])
     # Now create a policy target group
     pt_group_name = rutils.generate_random_name(prefix="rally_group_")
     self._create_policy_target_group(pt_group_name)
     self._update_policy_target_group(pt_group_name, provided_policy_rulesets=[ruleset_name])
Exemplo n.º 13
0
    def _get_server_group(self, clients):
        if self.config.get("placement_policy", None) is None:
            return

        return clients.nova().server_groups.create(
            name=rutils.generate_random_name(prefix="rally_server_group_"),
            policies=[self.config["placement_policy"]]
        ).id
Exemplo n.º 14
0
    def base_repo(self):
        """Get directory to clone tempest to

        old:
            _ rally/tempest
            |_base -> clone from source to here
            |_for-deployment-<UUID1> -> copy from relevant tempest base
            |_for-deployment-<UUID2> -> copy from relevant tempest base

        new:
            _ rally/tempest
            |_base
            ||_ tempest_base-<rand suffix specific for source> -> clone
            ||        from source to here
            ||_ tempest_base-<rand suffix 2>
            |_for-deployment-<UUID1> -> copy from relevant tempest base
            |_for-deployment-<UUID2> -> copy from relevant tempest base

        """
        if os.path.exists(Tempest.base_repo_dir):
            if self._is_git_repo(Tempest.base_repo_dir):
                # this is the old dir structure and needs to be upgraded
                directory = utils.generate_random_name("tempest_base-")
                LOG.debug("Upgrading Tempest directory tree: "
                          "Moving Tempest base dir %s into subdirectory %s" %
                          (Tempest.base_repo_dir, directory))
                self._move_contents_to_subdir(Tempest.base_repo_dir,
                                              directory)
            if not self._base_repo:
                # Search existing tempest bases for a matching source
                repos = [d for d in os.listdir(Tempest.base_repo_dir)
                         if self._is_git_repo(d) and
                         self.tempest_source == self._get_remote_origin(d)]
                if len(repos) > 1:
                    raise exceptions.MultipleMatchesFound(
                        needle="git directory",
                        haystack=repos)
                if repos:
                    # Use existing base with relevant source
                    self._base_repo = repos.pop()
        if not self._base_repo:
            directory = utils.generate_random_name("tempest_base-")
            self._base_repo = os.path.join(
                os.path.abspath(Tempest.base_repo_dir), directory)
        return self._base_repo
Exemplo n.º 15
0
    def base_repo(self):
        """Get directory to clone tempest to

        old:
            _ rally/tempest
            |_base -> clone from source to here
            |_for-deployment-<UUID1> -> copy from relevant tempest base
            |_for-deployment-<UUID2> -> copy from relevant tempest base

       new:
            _ rally/tempest
            |_base
            ||_ tempest_base-<rand suffix specific for source> -> clone
            ||        from source to here
            ||_ tempest_base-<rand suffix 2>
            |_for-deployment-<UUID1> -> copy from relevant tempest base
            |_for-deployment-<UUID2> -> copy from relevant tempest base

        """
        if os.path.exists(Tempest.base_repo_dir):
            if self._is_git_repo(Tempest.base_repo_dir):
                # this is the old dir structure and needs to be upgraded
                directory = utils.generate_random_name("tempest_base-")
                LOG.debug("Upgrading Tempest directory tree: "
                          "Moving Tempest base dir %s into subdirectory %s" %
                          (Tempest.base_repo_dir, directory))
                self._move_contents_to_subdir(Tempest.base_repo_dir, directory)
            if not self._base_repo:
                # Search existing tempest bases for a matching source
                repos = [
                    d for d in os.listdir(Tempest.base_repo_dir)
                    if self._is_git_repo(d)
                    and self.tempest_source == self._get_remote_origin(d)
                ]
                if len(repos) > 1:
                    raise exceptions.MultipleMatchesFound(
                        needle="git directory", haystack=repos)
                if repos:
                    # Use existing base with relevant source
                    self._base_repo = repos.pop()
        if not self._base_repo:
            directory = utils.generate_random_name("tempest_base-")
            self._base_repo = os.path.join(
                os.path.abspath(Tempest.base_repo_dir), directory)
        return self._base_repo
Exemplo n.º 16
0
 def create_and_update_policy_rule_set(self, classifier_args={}):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name,classifier_args['protocol'],
                                    classifier_args['port_range'], classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
     
     # Now create a policy rule set
     ruleset_name = rutils.generate_random_name(prefix="rally_ruleset_web_")
     self._create_policy_rule_set(ruleset_name, [rule_name])
     # Now create a new rule and add it in
     rule_name1 = rutils.generate_random_name(prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name1, classifier_name, action_name)
     self._update_policy_rule_set(ruleset_name, [rule_name, rule_name1])
Exemplo n.º 17
0
    def create_port(self, network_id, **kwargs):
        """Create neutron port.

        :param network_id: neutron network id
        :param **kwargs: POST /v2.0/ports request options
        :returns: neutron port dict
        """
        kwargs["network_id"] = network_id
        if "name" not in kwargs:
            kwargs["name"] = utils.generate_random_name("rally_port_")
        return self.client.create_port({"port": kwargs})["port"]
Exemplo n.º 18
0
    def create_port(self, network_id, **kwargs):
        """Create neutron port.

        :param network_id: neutron network id
        :param **kwargs: POST /v2.0/ports request options
        :returns: neutron port dict
        """
        kwargs["network_id"] = network_id
        if "name" not in kwargs:
            kwargs["name"] = utils.generate_random_name("rally_port_")
        return self.client.create_port({"port": kwargs})["port"]
Exemplo n.º 19
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: for compatibility, not used here
        :returns: dict, network data
        """
        cidr = self._generate_cidr()
        label = utils.generate_random_name("rally_net_")
        network = self.client.networks.create(
            project_id=tenant_id, cidr=cidr, label=label)
        return self._marshal_network_object(network)
Exemplo n.º 20
0
    def test_generate_random_name(self, mock_random):
        choice = "foobarspamchoicestring"

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(),
                         string.ascii_lowercase[:16])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(length=10),
                         string.ascii_lowercase[:10])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(choice=choice),
                         choice[:16])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(choice=choice, length=5),
                         choice[:5])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(prefix="foo_", length=10),
                         "foo_" + string.ascii_lowercase[:10])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(
            utils.generate_random_name(prefix="foo_", choice=choice,
                                       length=10), "foo_" + choice[:10])
Exemplo n.º 21
0
 def boot_vm(self, image, flavor, classifier_args={}, **kwargs):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(
         prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name,
                                    classifier_args['protocol'],
                                    classifier_args['port_range'],
                                    classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(
         prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
     # Now create a policy rule set
     ruleset_name = rutils.generate_random_name(prefix="rally_ruleset_web_")
     self._create_policy_rule_set(ruleset_name, [rule_name])
     # Now create a policy target group
     pt_group_name = rutils.generate_random_name(prefix="rally_group_")
     self._create_policy_target_group(pt_group_name)
     # Now update the policy target group
     self._update_policy_target_group(
         pt_group_name, provided_policy_rulesets=[ruleset_name])
     # Now create a policy target inside the group
     pt_name = rutils.generate_random_name(prefix="rally_target_web1")
     self._create_policy_target(pt_name, pt_group_name)
     # Get the port id based on the policy target
     port_id = self._show_policy_target(pt_name)
     kwargs["nics"] = [{"port-id": port_id}]
     instance = self._boot_server(image, flavor, **kwargs)
Exemplo n.º 22
0
    def test_generate_random_name(self, mock_random):
        choice = "foobarspamchoicestring"

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(),
                         string.ascii_lowercase[:16])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(length=10),
                         string.ascii_lowercase[:10])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(choice=choice),
                         choice[:16])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(utils.generate_random_name(choice=choice, length=5),
                         choice[:5])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(
            utils.generate_random_name(prefix="foo_", length=10),
            "foo_" + string.ascii_lowercase[:10])

        idx = iter(range(100))
        mock_random.choice.side_effect = lambda choice: choice[next(idx)]
        self.assertEqual(
            utils.generate_random_name(prefix="foo_",
                                       choice=choice, length=10),
            "foo_" + choice[:10])
Exemplo n.º 23
0
 def boot_vm(self, image, flavor, classifier_args= {}, **kwargs):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name)
     # Create a policy classifier
     classifier_name = rutils.generate_random_name(prefix="rally_classifier_web_traffic_")
     self._create_policy_classifier(classifier_name, classifier_args['protocol'],
                                    classifier_args['port_range'], classifier_args['direction'])
     # Now create a policy rule
     rule_name = rutils.generate_random_name(prefix="rally_rule_web_policy_")
     self._create_policy_rule(rule_name, classifier_name, action_name)
     # Now create a policy rule set
     ruleset_name = rutils.generate_random_name(prefix="rally_ruleset_web_")
     self._create_policy_rule_set(ruleset_name, [rule_name])
     # Now create a policy target group
     pt_group_name = rutils.generate_random_name(prefix="rally_group_")
     self._create_policy_target_group(pt_group_name)
     # Now update the policy target group
     self._update_policy_target_group(pt_group_name, provided_policy_rulesets=[ruleset_name])
     # Now create a policy target inside the group
     pt_name = rutils.generate_random_name(prefix="rally_target_web1")
     self._create_policy_target(pt_name,pt_group_name)
     # Get the port id based on the policy target
     port_id = self._show_policy_target(pt_name)
     kwargs["nics"] = [{"port-id": port_id}]
     instance = self._boot_server(image, flavor, **kwargs)
Exemplo n.º 24
0
 def _create_image(self, hadoop_version, image_url, plugin_name, user,
                   user_name):
     scenario = glance_utils.GlanceScenario({"user": user})
     image_name = rutils.generate_random_name(prefix="rally_sahara_image_")
     image = scenario._create_image(name=image_name,
                                    container_format="bare",
                                    image_location=image_url,
                                    disk_format="qcow2")
     scenario.clients("sahara").images.update_image(
         image_id=image.id, user_name=user_name, desc="")
     scenario.clients("sahara").images.update_tags(
         image_id=image.id, new_tags=[plugin_name, hadoop_version])
     return image.id
Exemplo n.º 25
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: for compatibility, not used here
        :returns: dict, network data
        """
        cidr = self._generate_cidr()
        label = utils.generate_random_name("rally_net_")
        network = self.client.networks.create(tenant_id=tenant_id,
                                              cidr=cidr,
                                              label=label)
        return self._marshal_network_object(network)
Exemplo n.º 26
0
 def _create_image(self, hadoop_version, image_url, plugin_name, user,
                   user_name):
     scenario = glance_utils.GlanceScenario({"user": user})
     image_name = rutils.generate_random_name(prefix="rally_sahara_image_")
     image = scenario._create_image(name=image_name,
                                    container_format="bare",
                                    image_location=image_url,
                                    disk_format="qcow2")
     scenario.clients("sahara").images.update_image(
         image_id=image.id, user_name=user_name, desc="")
     scenario.clients("sahara").images.update_tags(
         image_id=image.id, new_tags=[plugin_name, hadoop_version])
     return image.id
Exemplo n.º 27
0
    def create_router(self, external=False, **kwargs):
        """Create neutron router.

        :param external: bool, whether to set setup external_gateway_info
        :param **kwargs: POST /v2.0/routers request options
        :returns: neutron router dict
        """
        if "name" not in kwargs:
            kwargs["name"] = utils.generate_random_name("rally_router_")

        if external and "external_gateway_info" not in kwargs:
            for net in self.external_networks:
                kwargs["external_gateway_info"] = {"network_id": net["id"], "enable_snat": True}
        return self.client.create_router({"router": kwargs})["router"]
Exemplo n.º 28
0
    def create_router(self, external=False, **kwargs):
        """Create neutron router.

        :param external: bool, whether to set setup external_gateway_info
        :param **kwargs: POST /v2.0/routers request options
        :returns: neutron router dict
        """
        if "name" not in kwargs:
            kwargs["name"] = utils.generate_random_name("rally_router_")

        if external and "external_gateway_info" not in kwargs:
            for net in self.external_networks:
                kwargs["external_gateway_info"] = {
                    "network_id": net["id"], "enable_snat": True}
        return self.client.create_router({"router": kwargs})["router"]
Exemplo n.º 29
0
    def create_v1_pool(self, subnet_id, **kwargs):
        """Create LB Pool (v1).

        :param subnet_id: str, neutron subnet-id
        :param **kwargs: extra options
        :returns: neutron lb-pool dict
        """
        pool_args = {
            "pool": {
                "name": utils.generate_random_name("rally_pool_"),
                "subnet_id": subnet_id,
                "lb_method": kwargs.get("lb_method", self.LB_METHOD),
                "protocol": kwargs.get("protocol", self.LB_PROTOCOL)
            }
        }
        return self.client.create_pool(pool_args)
Exemplo n.º 30
0
    def create_v1_pool(self, subnet_id, **kwargs):
        """Create LB Pool (v1).

        :param subnet_id: str, neutron subnet-id
        :param **kwargs: extra options
        :returns: neutron lb-pool dict
        """
        pool_args = {
            "pool": {
                "name": utils.generate_random_name("rally_pool_"),
                "subnet_id": subnet_id,
                "lb_method": kwargs.get("lb_method", self.LB_METHOD),
                "protocol": kwargs.get("protocol", self.LB_PROTOCOL)
            }
        }
        return self.client.create_pool(pool_args)
Exemplo n.º 31
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: for compatibility, not used here
        :returns: dict, network data
        """
        cidr = self._generate_cidr()
        label = utils.generate_random_name("rally_net_")
        network = self.client.networks.create(
            tenant_id=tenant_id, cidr=cidr, label=label)
        return {"id": network.id,
                "cidr": network.cidr,
                "name": network.label,
                "status": "ACTIVE",
                "external": False,
                "tenant_id": tenant_id}
Exemplo n.º 32
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: Additional keyword arguments. Only
                         ``network_create_args`` is honored; other
                         arguments are accepted for compatibility, but
                         are not used here. ``network_create_args``
                         can be used to provide additional arbitrary
                         network creation arguments.
        :returns: dict, network data
        """
        cidr = self._generate_cidr()
        label = utils.generate_random_name("rally_net_")
        network_create_args = kwargs.get("network_create_args", {})
        network = self.client.networks.create(project_id=tenant_id, cidr=cidr, label=label, **network_create_args)
        return self._marshal_network_object(network)
Exemplo n.º 33
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: for compatibility, not used here
        :returns: dict, network data
        """
        cidr = self._generate_cidr()
        label = utils.generate_random_name("rally_net_")
        network = self.client.networks.create(
            tenant_id=tenant_id, cidr=cidr, label=label)
        return {"id": network.id,
                "cidr": network.cidr,
                "name": network.label,
                "status": "ACTIVE",
                "external": False,
                "tenant_id": tenant_id}
Exemplo n.º 34
0
    def _create_node(self, **kwargs):
        """Create node immediately.

        :param kwargs: optional parameters to create image
        :returns: node object
        """
        if "name" not in kwargs:
            # NOTE(rvasilets): can't use _generate_random_name() because
            # ironic have specific format for node name.
            # Check that the supplied hostname conforms to:
            # * http://en.wikipedia.org/wiki/Hostname
            # * http://tools.ietf.org/html/rfc952
            # * http://tools.ietf.org/html/rfc1123
            # or the name could be just uuid.
            kwargs["name"] = utils.generate_random_name(
                prefix="rally", choice=string.ascii_lowercase + string.digits)

        return self.admin_clients("ironic").node.create(**kwargs)
Exemplo n.º 35
0
    def _create_node(self, **kwargs):
        """Create node immediately.

        :param kwargs: optional parameters to create image
        :returns: node object
        """
        if "name" not in kwargs:
            # NOTE(rvasilets): can't use _generate_random_name() because
            # ironic have specific format for node name.
            # Check that the supplied hostname conforms to:
            # * http://en.wikipedia.org/wiki/Hostname
            # * http://tools.ietf.org/html/rfc952
            # * http://tools.ietf.org/html/rfc1123
            # or the name could be just uuid.
            kwargs["name"] = utils.generate_random_name(
                prefix="rally", choice=string.ascii_lowercase + string.digits)

        return self.admin_clients("ironic").node.create(**kwargs)
Exemplo n.º 36
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        :param tenant_id: str, tenant ID
        :param **kwargs: Additional keyword arguments. Only
                         ``network_create_args`` is honored; other
                         arguments are accepted for compatibility, but
                         are not used here. ``network_create_args``
                         can be used to provide additional arbitrary
                         network creation arguments.
        :returns: dict, network data
        """
        cidr = self._generate_cidr()
        label = utils.generate_random_name("rally_net_")
        network_create_args = kwargs.get("network_create_args", {})
        network = self.client.networks.create(project_id=tenant_id,
                                              cidr=cidr,
                                              label=label,
                                              **network_create_args)
        return self._marshal_network_object(network)
Exemplo n.º 37
0
    def create_volume(self, size, **kwargs):
        kwargs["name"] = kwargs.get("name", utils.generate_random_name())

        volume = self.client.volumes.create(size, **kwargs)
        return volume
Exemplo n.º 38
0
 def update_volume(self, volume, **update_args):
     update_args["name"] = update_args.get("name",
                                           utils.generate_random_name())
     update_args["description"] = update_args.get("description")
     self.client.volumes.update(volume, **update_args)
Exemplo n.º 39
0
 def create_snapshot(self, volume_id, **kwargs):
     kwargs["name"] = kwargs.get("name", utils.generate_random_name())
     snapshot = self.client.volume_snapshots.create(volume_id, **kwargs)
     return snapshot
Exemplo n.º 40
0
 def _generate_random_name(cls, prefix=None, length=None):
     prefix = cls.RESOURCE_NAME_PREFIX if prefix is None else prefix
     length = length or cls.RESOURCE_NAME_LENGTH
     return utils.generate_random_name(prefix, length)
Exemplo n.º 41
0
    def create_network(self, tenant_id, **kwargs):
        """Create network.

        The following keyword arguments are accepted:

        * add_router: Create an external router and add an interface to each
                      subnet created. Default: False
        * subnets_num: Number of subnets to create per network. Default: 0
        * dns_nameservers: Nameservers for each subnet. Default:
                           8.8.8.8, 8.8.4.4
        * network_create_args: Additional network creation arguments.

        :param tenant_id: str, tenant ID
        :param kwargs: Additional options, left open-ended for compatbilitiy.
                       See above for recognized keyword args.
        :returns: dict, network data
        """
        network_args = {"network": kwargs.get("network_create_args", {})}
        network_args["network"].update({
            "tenant_id":
            tenant_id,
            "name":
            utils.generate_random_name("rally_net_")
        })
        network = self.client.create_network(network_args)["network"]

        router = None
        if kwargs.get("add_router", False):
            router = self.create_router(external=True, tenant_id=tenant_id)

        subnets = []
        subnets_num = kwargs.get("subnets_num", 0)
        for i in range(subnets_num):
            subnet_args = {
                "subnet": {
                    "tenant_id":
                    tenant_id,
                    "network_id":
                    network["id"],
                    "name":
                    utils.generate_random_name("rally_subnet_"),
                    "ip_version":
                    self.SUBNET_IP_VERSION,
                    "cidr":
                    self._generate_cidr(),
                    "enable_dhcp":
                    True,
                    "dns_nameservers":
                    kwargs.get("dns_nameservers", ["8.8.8.8", "8.8.4.4"])
                }
            }
            subnet = self.client.create_subnet(subnet_args)["subnet"]
            subnets.append(subnet["id"])

            if router:
                self.client.add_interface_router(router["id"],
                                                 {"subnet_id": subnet["id"]})

        return {
            "id": network["id"],
            "name": network["name"],
            "status": network["status"],
            "subnets": subnets,
            "external": network.get("router:external", False),
            "router_id": router and router["id"] or None,
            "tenant_id": tenant_id
        }
Exemplo n.º 42
0
    def ping_and_ssh_group(self, image, flavor, **kwargs):
        """
        Scenario that has
        1. A provider group that provides icmp and ssh bidirectional
        2. 2 consumer groups that consumes icmp and ssh bidirectional
        """
        action_name = rutils.generate_random_name(prefix="rally_action_allow_")
        self._create_policy_action(name=action_name)
        
        # Create a policy classifier name for icmp and ssh
        classifier_name_icmp = rutils.generate_random_name(prefix="rally_classifier_icmp_")
        classifier_name_ssh = rutils.generate_random_name(prefix="rally_classifier_ssh_")
        # Create the policy classifier for ICMP
        self._create_policy_classifier(classifier_name_icmp, "icmp", None, "bi")
        # Create the policy classifier for SSH
        self._create_policy_classifier(classifier_name_ssh, "tcp", "22", "bi")
                                                          

        # Now create a policy rule for ICMP
        rule_name_icmp = rutils.generate_random_name(prefix="rally_rule_icmp_")
        self._create_policy_rule(rule_name_icmp, classifier_name_icmp, action_name)
        # Now create a policy rule for SSH
        rule_name_ssh = rutils.generate_random_name(prefix="rally_rule_ssh_")
        self._create_policy_rule(rule_name_ssh, classifier_name_ssh, action_name)
        
        # Now create a policy rule set for ICMP
        ruleset_name_icmp = rutils.generate_random_name(prefix="rally_ruleset_icmp_")
        self._create_policy_rule_set(ruleset_name_icmp, [rule_name_icmp])
        # Create another rule set for SSH
        ruleset_name_ssh = rutils.generate_random_name(prefix="rally_ruleset_ssh_")
        self._create_policy_rule_set(ruleset_name_ssh, [rule_name_ssh])
        
        # Create a policy target group that provides ICMP and SSH
        pt_group_name_provider = rutils.generate_random_name(prefix="rally_group_provider_")
        self._create_policy_target_group(pt_group_name_provider)
        # Now update the policy target group to provide ICMP and SSH
        self._update_policy_target_group(pt_group_name_provider, provided_policy_rulesets=[ruleset_name_icmp, ruleset_name_ssh])
        # Create another 2 policy target groups that consumes the ICMP and SSH
        pt_group_name_consumer_1 = rutils.generate_random_name(prefix="rally_group_consumer_1_")
        self._create_policy_target_group(pt_group_name_consumer_1)
        self._update_policy_target_group(pt_group_name_consumer_1, consumed_policy_rulesets=[ruleset_name_icmp, ruleset_name_ssh])
        pt_group_name_consumer_2 = rutils.generate_random_name(prefix="rally_group_consumer_2_")
        self._create_policy_target_group(pt_group_name_consumer_2)
        self._update_policy_target_group(pt_group_name_consumer_2, consumed_policy_rulesets=[ruleset_name_icmp, ruleset_name_ssh])

        
        # Create a policy target in the provider group
        pt_name_provider = rutils.generate_random_name(prefix="rally_target_provider_")
        self._create_policy_target(pt_name_provider, pt_group_name_provider)
        port_id_provider = self._show_policy_target(pt_name_provider)
        
        # Create a policy target in the consumer 1 group
        pt_name_consumer_1 = rutils.generate_random_name(prefix="rally_target_consumer_1_")
        self._create_policy_target(pt_name_consumer_1, pt_group_name_consumer_1)
        port_id_consumer_1 = self._show_policy_target(pt_name_consumer_1)
        
        # Create a policy target in the consumer 2 group
        pt_name_consumer_2 = rutils.generate_random_name(prefix="rally_target_consumer_2_")
        self._create_policy_target(pt_name_consumer_2, pt_group_name_consumer_2)
        port_id_consumer_2 = self._show_policy_target(pt_name_consumer_2)
        
        # Create a VM in provider group
        kwargs["nics"] = [{"port-id": port_id_provider}]
        instance_provider = self._boot_server(image, flavor, **kwargs)
        
        # Create a VM in the consumer1 group
        kwargs["nics"] = [{"port-id": port_id_consumer_1}]
        instance_consumer_1 = self._boot_server(image, flavor, **kwargs)
        
        # Create a VM in the consumer 2 group
        kwargs["nics"] = [{"port-id": port_id_consumer_2}]
        instance_consumer_2 = self._boot_server(image, flavor, **kwargs)
Exemplo n.º 43
0
 def create_and_delete_policy_action(self, action_type="allow"):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name, type=action_type)
     self._delete_policy_action(name=action_name)
Exemplo n.º 44
0
 def create_and_delete_policy_action(self, action_type="allow"):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name, type=action_type)
     self._delete_policy_action(name=action_name)
Exemplo n.º 45
0
    def ping_and_ssh_group(self, image, flavor, **kwargs):
        """
        Scenario that has
        1. A provider group that provides icmp and ssh bidirectional
        2. 2 consumer groups that consumes icmp and ssh bidirectional
        """
        action_name = rutils.generate_random_name(prefix="rally_action_allow_")
        self._create_policy_action(name=action_name)

        # Create a policy classifier name for icmp and ssh
        classifier_name_icmp = rutils.generate_random_name(
            prefix="rally_classifier_icmp_")
        classifier_name_ssh = rutils.generate_random_name(
            prefix="rally_classifier_ssh_")
        # Create the policy classifier for ICMP
        self._create_policy_classifier(classifier_name_icmp, "icmp", None,
                                       "bi")
        # Create the policy classifier for SSH
        self._create_policy_classifier(classifier_name_ssh, "tcp", "22", "bi")

        # Now create a policy rule for ICMP
        rule_name_icmp = rutils.generate_random_name(prefix="rally_rule_icmp_")
        self._create_policy_rule(rule_name_icmp, classifier_name_icmp,
                                 action_name)
        # Now create a policy rule for SSH
        rule_name_ssh = rutils.generate_random_name(prefix="rally_rule_ssh_")
        self._create_policy_rule(rule_name_ssh, classifier_name_ssh,
                                 action_name)

        # Now create a policy rule set for ICMP
        ruleset_name_icmp = rutils.generate_random_name(
            prefix="rally_ruleset_icmp_")
        self._create_policy_rule_set(ruleset_name_icmp, [rule_name_icmp])
        # Create another rule set for SSH
        ruleset_name_ssh = rutils.generate_random_name(
            prefix="rally_ruleset_ssh_")
        self._create_policy_rule_set(ruleset_name_ssh, [rule_name_ssh])

        # Create a policy target group that provides ICMP and SSH
        pt_group_name_provider = rutils.generate_random_name(
            prefix="rally_group_provider_")
        self._create_policy_target_group(pt_group_name_provider)
        # Now update the policy target group to provide ICMP and SSH
        self._update_policy_target_group(
            pt_group_name_provider,
            provided_policy_rulesets=[ruleset_name_icmp, ruleset_name_ssh])
        # Create another 2 policy target groups that consumes the ICMP and SSH
        pt_group_name_consumer_1 = rutils.generate_random_name(
            prefix="rally_group_consumer_1_")
        self._create_policy_target_group(pt_group_name_consumer_1)
        self._update_policy_target_group(
            pt_group_name_consumer_1,
            consumed_policy_rulesets=[ruleset_name_icmp, ruleset_name_ssh])
        pt_group_name_consumer_2 = rutils.generate_random_name(
            prefix="rally_group_consumer_2_")
        self._create_policy_target_group(pt_group_name_consumer_2)
        self._update_policy_target_group(
            pt_group_name_consumer_2,
            consumed_policy_rulesets=[ruleset_name_icmp, ruleset_name_ssh])

        # Create a policy target in the provider group
        pt_name_provider = rutils.generate_random_name(
            prefix="rally_target_provider_")
        self._create_policy_target(pt_name_provider, pt_group_name_provider)
        port_id_provider = self._show_policy_target(pt_name_provider)

        # Create a policy target in the consumer 1 group
        pt_name_consumer_1 = rutils.generate_random_name(
            prefix="rally_target_consumer_1_")
        self._create_policy_target(pt_name_consumer_1,
                                   pt_group_name_consumer_1)
        port_id_consumer_1 = self._show_policy_target(pt_name_consumer_1)

        # Create a policy target in the consumer 2 group
        pt_name_consumer_2 = rutils.generate_random_name(
            prefix="rally_target_consumer_2_")
        self._create_policy_target(pt_name_consumer_2,
                                   pt_group_name_consumer_2)
        port_id_consumer_2 = self._show_policy_target(pt_name_consumer_2)

        # Create a VM in provider group
        kwargs["nics"] = [{"port-id": port_id_provider}]
        instance_provider = self._boot_server(image, flavor, **kwargs)

        # Create a VM in the consumer1 group
        kwargs["nics"] = [{"port-id": port_id_consumer_1}]
        instance_consumer_1 = self._boot_server(image, flavor, **kwargs)

        # Create a VM in the consumer 2 group
        kwargs["nics"] = [{"port-id": port_id_consumer_2}]
        instance_consumer_2 = self._boot_server(image, flavor, **kwargs)
Exemplo n.º 46
0
 def _generate_random_name(cls, prefix=None, length=None):
     prefix = cls.RESOURCE_NAME_PREFIX if prefix is None else prefix
     length = length or cls.RESOURCE_NAME_LENGTH
     return utils.generate_random_name(prefix, length)
Exemplo n.º 47
0
 def create_and_update_policy_action(self, action_type="allow"):
     action_name = rutils.generate_random_name(prefix="rally_action_allow_")
     self._create_policy_action(name=action_name, type=action_type)
     # Create a new action name and update
     action_name1 = rutils.generate_random_name(prefix="rally_action_allow_")
     self._update_policy_action(name=action_name, new_name=action_name1)