Skip to content

Commit

Permalink
Changes for all policy API
Browse files Browse the repository at this point in the history
  • Loading branch information
akalambu committed Jun 4, 2015
1 parent d753f6d commit d3f3377
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
34 changes: 22 additions & 12 deletions rally/plugins/openstack/scenarios/gbp/gbp.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
from rally.benchmark.scenarios import base
from rally.plugins.openstack.scenarios.gbp import utils
import time
from rally.common import utils as rutils
class GBPTests(utils.GBPScenario):
"""Bechmark scenarios for Group Based Policy"""

@base.scenario()
def test_gbp(self, gbp_args=None):
self._create_policy_action()
action_name = rutils.generate_random_name(prefix="rally_action_allow_")
self._create_policy_action(name=action_name)
# Create a policy classifier
self._create_policy_classifier("web-traffic","tcp", "80", "in")
# Now create a policy rule
self._create_policy_rule("web-policy-rule", "web-traffic", "allow")
classifier_name = rutils.generate_random_name(prefix="rally_classifier_web_traffic_")
self._create_policy_classifier(classifier_name,"tcp", "80", "in")
# 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
self._create_policy_rule_set("web-ruleset", ["web-policy-rule"])
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
self._create_policy_target_group("web")
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("web", provided_policy_rulesets=["web-ruleset"])
self._update_policy_target_group(pt_group_name, provided_policy_rulesets=[ruleset_name])
# Now create a policy target inside the group
self._delete_policy_target_group("web")
self._delete_policy_rule_set("web-ruleset")
self._delete_policy_rule("web-policy-rule")
self._delete_policy_classifier("web-traffic")
self._delete_policy_action()
pt_name = rutils.generate_random_name(prefix="rally_target_web1")
self._create_policy_target(pt_name,pt_group_name)
# Delete all created resources
self._delete_policy_target(pt_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)
42 changes: 37 additions & 5 deletions rally/plugins/openstack/scenarios/gbp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rally import osclients
import os


@osclients.Clients.register("gbp")
def gbp(self):
from gbpclient.v2_0 import client as gbpclient
Expand Down Expand Up @@ -33,7 +34,6 @@ def _delete_policy_action(self, name="allow"):
for i in range(10):
policy_id = self._find_policy_actions(name)
if policy_id:
print "Deleting policy action %s" %(policy_id)
self.clients("gbp").delete_policy_action(policy_id)
return
print "Policy action %s not found" %(name)
Expand Down Expand Up @@ -66,7 +66,6 @@ def _delete_policy_classifier(self, name):
for i in range(10):
classifier_id = self._find_policy_classifier(name)
if classifier_id:
print "Deleting classifier id %s" %(classifier_id)
self.clients("gbp").delete_policy_classifier(classifier_id)
return
print "Policy classifier %s is not found" %(name)
Expand Down Expand Up @@ -108,7 +107,6 @@ def _delete_policy_rule(self, name):
for i in range(10):
policy_rule_id = self._find_policy_rule(name)
if policy_rule_id:
print "Deleting policy rule %s" %(policy_rule_id)
self.clients("gbp").delete_policy_rule(policy_rule_id)
return
print "Policy rule %s not found" %(name)
Expand Down Expand Up @@ -144,7 +142,6 @@ def _delete_policy_rule_set(self, name):
for i in range(10):
policy_ruleset_id = self._find_policy_rule_set(name)
if policy_ruleset_id:
print "Deleting Policy rule set %s" %(policy_ruleset_id)
self.clients("gbp").delete_policy_rule_set(policy_ruleset_id)
return
print "Policy rule set %s not found" %(name)
Expand Down Expand Up @@ -174,7 +171,6 @@ def _delete_policy_target_group(self, name):
for i in range(10):
group_id = self._find_policy_target_group(name)
if group_id:
print "Deleting Policy target group %s" %(group_id)
self.clients("gbp").delete_policy_target_group(group_id)
return
print "Policy target group %s not found" %(name)
Expand Down Expand Up @@ -202,4 +198,40 @@ def _update_policy_target_group(self, group_name, consumed_policy_rulesets=None,
}
}
self.clients("gbp").update_policy_target_group(group_id, body)

@base.atomic_action_timer("gbp.create_policy_target")
def _create_policy_target(self, name, group_name):
# Lookup the group id first
group_id = self._find_policy_target_group(group_name)
body = {
"policy_target": {
"policy_target_group_id": group_id,
"name": name
}
}
self.clients("gbp").create_policy_target(body)

def _find_policy_target(self, name):
targets = self.clients("gbp").list_policy_targets()
for target in targets["policy_targets"]:
if target['name'] == name:
return target['id']
return None

@base.atomic_action_timer("gbp.delete_policy_target")
def _delete_policy_target(self, name):
for i in range(10):
target_id = self._find_policy_target(name)
if target_id:
self.clients("gbp").delete_policy_target(target_id)
return
print "Policy target %s not found" %(name)
return








4 changes: 2 additions & 2 deletions samples/tasks/scenarios/gbp/gbp.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"runner": {
"type": "constant",
"times": 1,
"concurrency": 1
"times": 10,
"concurrency": 10
},
"context": {
"users": {
Expand Down

0 comments on commit d3f3377

Please sign in to comment.