Skip to content

Commit

Permalink
Changes for context and cleanup to enable scale
Browse files Browse the repository at this point in the history
  • Loading branch information
akalambu committed Jun 6, 2015
1 parent 41822b4 commit 468ea0e
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 34 deletions.
54 changes: 54 additions & 0 deletions rally/plugins/openstack/context/cleanup/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,60 @@ def list(self):
return [self.tenant_uuid] if self.tenant_uuid else []


# Group Based policy
_grouppolicy_order = get_order(275)

@base.resource(service=None, resource=None, admin_required=True)
class GroupPolicyMixin(SynchronizedDeletion, base.ResourceManager):

def _manager(self):
client = self._admin_required and self.admin or self.user
return getattr(client, self._service)()

def id(self):
return self.raw_resource["id"]

def delete(self):
delete_method = getattr(self._manager(), "delete_%s" % self._resource)
delete_method(self.id())

def list(self):
resources = self._resource + "s"
list_method = getattr(self._manager(), "list_%s" % resources)

return filter(lambda r: r["tenant_id"] == self.tenant_uuid,
list_method({"tenant_id": self.tenant_uuid})[resources])

@base.resource("grouppolicy", "policy_target", order=next(_grouppolicy_order),
tenant_resource=True)
class GroupPolicyTarget(GroupPolicyMixin):
pass

@base.resource("grouppolicy", "policy_target_group", order=next(_grouppolicy_order),
tenant_resource=True)
class GroupPolicyTargetGroup(GroupPolicyMixin):
pass

@base.resource("grouppolicy", "policy_rule_set", order=next(_grouppolicy_order),
tenant_resource=True)
class GroupPolicyRuleSet(GroupPolicyMixin):
pass

@base.resource("grouppolicy", "policy_rule", order=next(_grouppolicy_order),
tenant_resource=True)
class GroupPolicyRule(GroupPolicyMixin):
pass

@base.resource("grouppolicy", "policy_classifier", order=next(_grouppolicy_order),
tenant_resource=True)
class GroupPolicyClassifier(GroupPolicyMixin):
pass

@base.resource("grouppolicy", "policy_action", order=next(_grouppolicy_order),
tenant_resource=True)
class GroupPolicyAction(GroupPolicyMixin):
pass

# HEAT

@base.resource("heat", "stacks", order=100, tenant_resource=True)
Expand Down
95 changes: 88 additions & 7 deletions rally/plugins/openstack/scenarios/gbp/gbp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
from rally.common import utils as rutils
class GBPTests(utils.GBPScenario):
"""Benchmark scenarios for Group Based Policy"""


@base.scenario(context={"cleanup":["grouppolicy"]})
def create_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)

@base.scenario()
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)

@base.scenario(context={"cleanup": ["grouppolicy"]})
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'])

@base.scenario()
def create_and_delete_policy_classifier(self, classifier_args={}):
action_name = rutils.generate_random_name(prefix="rally_action_allow_")
Expand All @@ -21,6 +34,19 @@ def create_and_delete_policy_classifier(self, classifier_args={}):
self._delete_policy_classifier(classifier_name)
self._delete_policy_action(name=action_name)

@base.scenario(context={"cleanup": ["grouppolicy"]})
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)


@base.scenario()
def create_and_delete_policy_rule(self, classifier_args={}):
action_name = rutils.generate_random_name(prefix="rally_action_allow_")
Expand All @@ -36,6 +62,22 @@ def create_and_delete_policy_rule(self, classifier_args={}):
self._delete_policy_classifier(classifier_name)
self._delete_policy_action(name=action_name)

@base.scenario(context={"cleanup": ["grouppolicy"]})
def create_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])


@base.scenario()
def create_and_delete_policy_rule_set(self, classifier_args={}):
action_name = rutils.generate_random_name(prefix="rally_action_allow_")
Expand All @@ -55,6 +97,24 @@ def create_and_delete_policy_rule_set(self, classifier_args={}):
self._delete_policy_classifier(classifier_name)
self._delete_policy_action(name=action_name)

@base.scenario(context={"cleanup": ["grouppolicy"]})
def create_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)

@base.scenario()
def create_and_delete_policy_target_group(self, classifier_args={}):
action_name = rutils.generate_random_name(prefix="rally_action_allow_")
Expand All @@ -78,7 +138,7 @@ def create_and_delete_policy_target_group(self, classifier_args={}):
self._delete_policy_classifier(classifier_name)
self._delete_policy_action(name=action_name)

@base.scenario()
@base.scenario(context={"cleanup": ["grouppolicy"]})
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)
Expand All @@ -96,11 +156,32 @@ def create_and_update_policy_target_group(self, classifier_args={}):
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])
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)


@base.scenario(context={"cleanup": ["grouppolicy"]})
def create_policy_target(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)
# 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)



@base.scenario()
def create_and_delete_policy_target(self, classifier_args={}):
Expand Down
42 changes: 21 additions & 21 deletions rally/plugins/openstack/scenarios/gbp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import time

@osclients.Clients.register("gbp")
def gbp(self):
@osclients.Clients.register("grouppolicy")
def grouppolicy(self):
from gbpclient.v2_0 import client as gbpclient
return gbpclient.Client(username=self.endpoint.username,
password=self.endpoint.password,
Expand All @@ -23,7 +23,7 @@ def _create_policy_action(self, name="allow", type="allow"):
"action_type": type
}
}
self.clients("gbp").create_policy_action(body)
self.clients("grouppolicy").create_policy_action(body)

@base.atomic_action_timer("gbp.delete_policy_action")
def _delete_policy_action(self, name="allow"):
Expand All @@ -33,7 +33,7 @@ def _delete_policy_action(self, name="allow"):
"""
policy_id = self._find_policy_actions(name)
if policy_id:
self.clients("gbp").delete_policy_action(policy_id)
self.clients("grouppolicy").delete_policy_action(policy_id)
return
print "Policy action %s not found" %(name)
return
Expand All @@ -44,7 +44,7 @@ def _find_policy_actions(self,name):
Lookup 10 second interval
"""
for i in range(10):
actions = self.clients("gbp").list_policy_actions()
actions = self.clients("grouppolicy").list_policy_actions()
for policy in actions['policy_actions']:
if policy['name'] == name:
return policy['id']
Expand All @@ -61,13 +61,13 @@ def _create_policy_classifier(self, name, protocol, port_range, direction):
"direction": direction
}
}
self.clients("gbp").create_policy_classifier(body)
self.clients("grouppolicy").create_policy_classifier(body)

@base.atomic_action_timer("gbp.delete_policy_classifier")
def _delete_policy_classifier(self, name):
classifier_id = self._find_policy_classifier(name)
if classifier_id:
self.clients("gbp").delete_policy_classifier(classifier_id)
self.clients("grouppolicy").delete_policy_classifier(classifier_id)
return
print "Policy classifier %s is not found" %(name)
return
Expand All @@ -77,7 +77,7 @@ def _find_policy_classifier(self, name):
Find a policy classifier given its name
"""
for i in range(10):
classifiers = self.clients("gbp").list_policy_classifiers()
classifiers = self.clients("grouppolicy").list_policy_classifiers()
for classifier in classifiers["policy_classifiers"]:
if classifier['name'] == name:
return classifier['id']
Expand All @@ -93,14 +93,14 @@ def _create_policy_rule(self, policy_name, classifier_name, action_name):
"name": policy_name
}
}
self.clients("gbp").create_policy_rule(body)
self.clients("grouppolicy").create_policy_rule(body)

def _find_policy_rule(self, name):
"""
Find a policy rule given its name
"""
for i in range(10):
rules = self.clients("gbp").list_policy_rules()
rules = self.clients("grouppolicy").list_policy_rules()
for rule in rules["policy_rules"]:
if rule['name'] == name:
return rule['id']
Expand All @@ -111,7 +111,7 @@ def _find_policy_rule(self, name):
def _delete_policy_rule(self, name):
policy_rule_id = self._find_policy_rule(name)
if policy_rule_id:
self.clients("gbp").delete_policy_rule(policy_rule_id)
self.clients("grouppolicy").delete_policy_rule(policy_rule_id)
return
print "Policy rule %s not found" %(name)
return
Expand All @@ -129,14 +129,14 @@ def _create_policy_rule_set(self, ruleset_name, rules_list):
"policy_rules": ruleid_list
}
}
self.clients("gbp").create_policy_rule_set(body)
self.clients("grouppolicy").create_policy_rule_set(body)

def _find_policy_rule_set(self, name):
"""
Find a policy rule set given its name
"""
for i in range(10):
rule_set = self.clients("gbp").list_policy_rule_sets()
rule_set = self.clients("grouppolicy").list_policy_rule_sets()
for ruleset in rule_set["policy_rule_sets"]:
if ruleset['name'] == name:
return ruleset['id']
Expand All @@ -147,7 +147,7 @@ def _find_policy_rule_set(self, name):
def _delete_policy_rule_set(self, name):
policy_ruleset_id = self._find_policy_rule_set(name)
if policy_ruleset_id:
self.clients("gbp").delete_policy_rule_set(policy_ruleset_id)
self.clients("grouppolicy").delete_policy_rule_set(policy_ruleset_id)
return
print "Policy rule set %s not found" %(name)
return
Expand All @@ -159,14 +159,14 @@ def _create_policy_target_group(self, name):
"name": name
}
}
self.clients("gbp").create_policy_target_group(body)
self.clients("grouppolicy").create_policy_target_group(body)

def _find_policy_target_group(self, name):
"""
Find a policy target group given the name
"""
for i in range(10):
groups = self.clients("gbp").list_policy_target_groups()
groups = self.clients("grouppolicy").list_policy_target_groups()
for group in groups["policy_target_groups"]:
if group['name'] == name:
return group['id']
Expand All @@ -177,7 +177,7 @@ def _find_policy_target_group(self, name):
def _delete_policy_target_group(self, name):
group_id = self._find_policy_target_group(name)
if group_id:
self.clients("gbp").delete_policy_target_group(group_id)
self.clients("grouppolicy").delete_policy_target_group(group_id)
return
print "Policy target group %s not found" %(name)
return
Expand All @@ -203,7 +203,7 @@ def _update_policy_target_group(self, group_name, consumed_policy_rulesets=None,
"consumed_policy_rule_sets" : consumed_dict
}
}
self.clients("gbp").update_policy_target_group(group_id, body)
self.clients("grouppolicy").update_policy_target_group(group_id, body)

@base.atomic_action_timer("gbp.create_policy_target")
def _create_policy_target(self, name, group_name):
Expand All @@ -215,11 +215,11 @@ def _create_policy_target(self, name, group_name):
"name": name
}
}
self.clients("gbp").create_policy_target(body)
self.clients("grouppolicy").create_policy_target(body)

def _find_policy_target(self, name):
for i in range(10):
targets = self.clients("gbp").list_policy_targets()
targets = self.clients("grouppolicy").list_policy_targets()
for target in targets["policy_targets"]:
if target['name'] == name:
return target['id']
Expand All @@ -230,7 +230,7 @@ def _find_policy_target(self, name):
def _delete_policy_target(self, name):
target_id = self._find_policy_target(name)
if target_id:
self.clients("gbp").delete_policy_target(target_id)
self.clients("grouppolicy").delete_policy_target(target_id)
return
print "Policy target %s not found" %(name)
return
Loading

0 comments on commit 468ea0e

Please sign in to comment.