summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKC Wang <kuangching.wang@gmail.com>2013-06-13 00:07:03 -0700
committerKC Wang <kuangching.wang@gmail.com>2013-08-02 02:08:37 -0700
commitd04f3822b5b7ef8d6c918c753a6e7733bdda0344 (patch)
treee30d1ddbcf4d3fd0f07807d836896f7373dd52ba /tests
parentfad71220eaf3c3c9b30ce4f16207967eab5ec2a9 (diff)
downloadpython-neutronclient-d04f3822b5b7ef8d6c918c753a6e7733bdda0344.tar.gz
FWaaS Client and Cli
Change-Id: Ie7faeb604e0813401e5d1816a8f7c6791a16b001 Implements: blueprint fwaas-client-cli
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/fw/__init__.py18
-rw-r--r--tests/unit/fw/test_cli20_firewall.py126
-rw-r--r--tests/unit/fw/test_cli20_firewallpolicy.py214
-rw-r--r--tests/unit/fw/test_cli20_firewallrule.py158
-rw-r--r--tests/unit/test_cli20.py6
5 files changed, 520 insertions, 2 deletions
diff --git a/tests/unit/fw/__init__.py b/tests/unit/fw/__init__.py
new file mode 100644
index 0000000..c4fafc1
--- /dev/null
+++ b/tests/unit/fw/__init__.py
@@ -0,0 +1,18 @@
+# Copyright 2013 Big Switch Networks Inc.
+# All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# @author: KC Wang, Big Switch Networks Inc.
+#
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
diff --git a/tests/unit/fw/test_cli20_firewall.py b/tests/unit/fw/test_cli20_firewall.py
new file mode 100644
index 0000000..ddaf1ca
--- /dev/null
+++ b/tests/unit/fw/test_cli20_firewall.py
@@ -0,0 +1,126 @@
+# Copyright 2013 Big Switch Networks Inc.
+# All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# @author: KC Wang, Big Switch Networks Inc.
+#
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+import sys
+
+from neutronclient.neutron.v2_0.fw import firewall
+from tests.unit import test_cli20
+
+
+class CLITestV20FirewallJSON(test_cli20.CLITestV20Base):
+
+ def test_create_firewall_with_mandatory_params(self):
+ """firewall-create with mandatory (none) params."""
+ resource = 'firewall'
+ cmd = firewall.CreateFirewall(test_cli20.MyApp(sys.stdout), None)
+ name = ''
+ tenant_id = 'my-tenant'
+ my_id = 'my-id'
+ policy_id = 'my-policy-id'
+ args = ['--tenant-id', tenant_id, policy_id, ]
+ position_names = ['firewall_policy_id', ]
+ position_values = [policy_id, ]
+ self._test_create_resource(resource, cmd, name, my_id, args,
+ position_names, position_values,
+ admin_state_up=True, tenant_id=tenant_id)
+
+ def test_create_firewall_with_all_params(self):
+ """firewall-create with all params set."""
+ resource = 'firewall'
+ cmd = firewall.CreateFirewall(test_cli20.MyApp(sys.stdout), None)
+ name = 'my-name'
+ description = 'my-desc'
+ policy_id = 'my-policy-id'
+ tenant_id = 'my-tenant'
+ my_id = 'my-id'
+ args = ['--description', description,
+ '--shared',
+ '--admin-state-down',
+ '--tenant-id', tenant_id,
+ policy_id]
+ position_names = ['firewall_policy_id', ]
+ position_values = [policy_id, ]
+ self._test_create_resource(resource, cmd, name, my_id, args,
+ position_names, position_values,
+ description=description,
+ shared=True, admin_state_up=False,
+ tenant_id=tenant_id)
+
+ def test_list_firewalls(self):
+ """firewall-list."""
+ resources = "firewalls"
+ cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
+ self._test_list_resources(resources, cmd, True)
+
+ def test_list_firewalls_pagination(self):
+ """firewall-list with pagination."""
+ resources = "firewalls"
+ cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
+ self._test_list_resources_with_pagination(resources, cmd)
+
+ def test_list_firewalls_sort(self):
+ """sorted list: firewall-list --sort-key name --sort-key id
+ --sort-key asc --sort-key desc
+ """
+ resources = "firewalls"
+ cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
+ self._test_list_resources(resources, cmd,
+ sort_key=["name", "id"],
+ sort_dir=["asc", "desc"])
+
+ def test_list_firewalls_limit(self):
+ """size (1000) limited list: firewall-list -P."""
+ resources = "firewalls"
+ cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
+ self._test_list_resources(resources, cmd, page_size=1000)
+
+ def test_show_firewall_id(self):
+ """firewall-show test_id."""
+ resource = 'firewall'
+ cmd = firewall.ShowFirewall(test_cli20.MyApp(sys.stdout), None)
+ args = ['--fields', 'id', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
+
+ def test_show_firewall_id_name(self):
+ """firewall-show."""
+ resource = 'firewall'
+ cmd = firewall.ShowFirewall(test_cli20.MyApp(sys.stdout), None)
+ args = ['--fields', 'id', '--fields', 'name', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id,
+ args, ['id', 'name'])
+
+ def test_update_firewall(self):
+ """firewall-update myid --name newname --tags a b."""
+ resource = 'firewall'
+ cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
+ self._test_update_resource(resource, cmd, 'myid',
+ ['myid', '--name', 'newname'],
+ {'name': 'newname', })
+
+ def test_delete_firewall(self):
+ """firewall-delete my-id."""
+ resource = 'firewall'
+ cmd = firewall.DeleteFirewall(test_cli20.MyApp(sys.stdout), None)
+ my_id = 'my-id'
+ args = [my_id]
+ self._test_delete_resource(resource, cmd, my_id, args)
+
+
+class CLITestV20FirewallXML(CLITestV20FirewallJSON):
+ format = 'xml'
diff --git a/tests/unit/fw/test_cli20_firewallpolicy.py b/tests/unit/fw/test_cli20_firewallpolicy.py
new file mode 100644
index 0000000..c5aba47
--- /dev/null
+++ b/tests/unit/fw/test_cli20_firewallpolicy.py
@@ -0,0 +1,214 @@
+# Copyright 2013 Big Switch Networks Inc.
+# All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# @author: KC Wang, Big Switch Networks Inc.
+#
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+import sys
+
+import mox
+
+from neutronclient.neutron.v2_0.fw import firewallpolicy
+from neutronclient import shell
+from tests.unit import test_cli20
+
+
+class CLITestV20FirewallPolicyJSON(test_cli20.CLITestV20Base):
+ def setUp(self):
+ super(CLITestV20FirewallPolicyJSON, self).setUp()
+
+ def test_create_firewall_policy_with_mandatory_params(self):
+ """firewall-policy-create with mandatory (none) params only."""
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.CreateFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ tenant_id = 'my-tenant'
+ name = 'my-name'
+ my_id = 'myid'
+ args = ['--tenant-id', tenant_id,
+ '--admin-state_up',
+ name, ]
+ position_names = ['name', ]
+ position_values = [name, ]
+ self._test_create_resource(resource, cmd, name, my_id, args,
+ position_names, position_values,
+ admin_state_up=True, tenant_id=tenant_id)
+
+ def test_create_firewall_policy_with_all_params(self):
+ """firewall-policy-create with all params set."""
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.CreateFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ name = 'my-name'
+ description = 'my-desc'
+ firewall_rules_arg = 'rule_id1 rule_id2'
+ firewall_rules_res = ['rule_id1', 'rule_id2']
+ tenant_id = 'my-tenant'
+ my_id = 'myid'
+ args = ['--description', description,
+ '--shared',
+ '--firewall-rules', firewall_rules_arg,
+ '--audited',
+ '--tenant-id', tenant_id,
+ '--admin-state_up',
+ name]
+ position_names = ['name', ]
+ position_values = [name, ]
+ self._test_create_resource(resource, cmd, name, my_id, args,
+ position_names, position_values,
+ description=description, shared=True,
+ firewall_rules=firewall_rules_res,
+ audited=True, admin_state_up=True,
+ tenant_id=tenant_id)
+
+ def test_list_firewall_policies(self):
+ """firewall-policy-list."""
+ resources = "firewall_policies"
+ cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources(resources, cmd, True)
+
+ def test_list_firewall_policies_pagination(self):
+ """firewall-policy-list."""
+ resources = "firewall_policies"
+ cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources_with_pagination(resources, cmd)
+
+ def test_list_firewall_policies_sort(self):
+ """sorted list: firewall-policy-list --sort-key name --sort-key id
+ --sort-key asc --sort-key desc
+ """
+ resources = "firewall_policies"
+ cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources(resources, cmd,
+ sort_key=["name", "id"],
+ sort_dir=["asc", "desc"])
+
+ def test_list_firewall_policies_limit(self):
+ """size (1000) limited list: firewall-policy-list -P."""
+ resources = "firewall_policies"
+ cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources(resources, cmd, page_size=1000)
+
+ def test_show_firewall_policy_id(self):
+ """firewall-policy-show test_id."""
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.ShowFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ args = ['--fields', 'id', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
+
+ def test_show_firewall_policy_id_name(self):
+ """firewall-policy-show."""
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.ShowFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ args = ['--fields', 'id', '--fields', 'name', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id,
+ args, ['id', 'name'])
+
+ def test_update_firewall_policy(self):
+ """firewall-policy-update myid --name newname."""
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.UpdateFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_update_resource(resource, cmd, 'myid',
+ ['myid', '--name', 'newname'],
+ {'name': 'newname', })
+
+ def test_delete_firewall_policy(self):
+ """firewall-policy-delete my-id."""
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.DeleteFirewallPolicy(test_cli20.MyApp(sys.stdout),
+ None)
+ my_id = 'myid1'
+ args = [my_id]
+ self._test_delete_resource(resource, cmd, my_id, args)
+
+ def test_insert_firewall_rule(self):
+ """firewall-policy-insert-rule myid newruleid
+ --insert-before ruleAid
+ --insert-after ruleBid
+ """
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.FirewallPolicyInsertRule(
+ test_cli20.MyApp(sys.stdout),
+ None)
+ myid = 'myid'
+ args = ['myid', 'newrule',
+ '--insert-before', 'rule2',
+ '--insert-after', 'rule1']
+ extrafields = {'firewall_rule_id': 'newrule',
+ 'insert_before': 'rule2',
+ 'insert_after': 'rule1'}
+
+ self.mox.StubOutWithMock(cmd, "get_client")
+ self.mox.StubOutWithMock(self.client.httpclient, "request")
+ cmd.get_client().MultipleTimes().AndReturn(self.client)
+ body = extrafields
+ path = getattr(self.client, resource + "_insert_path")
+ self.client.httpclient.request(
+ test_cli20.MyUrlComparator(
+ test_cli20.end_url(path % myid, format=self.format),
+ self.client),
+ 'PUT', body=test_cli20.MyComparator(body, self.client),
+ headers=mox.ContainsKeyValue(
+ 'X-Auth-Token',
+ test_cli20.TOKEN)).AndReturn((test_cli20.MyResp(204), None))
+ args.extend(['--request-format', self.format])
+ self.mox.ReplayAll()
+ cmd_parser = cmd.get_parser(resource + "_insert_rule")
+ shell.run_command(cmd, cmd_parser, args)
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+
+ def test_remove_firewall_rule(self):
+ """firewall-policy-remove-rule myid ruleid
+ """
+ resource = 'firewall_policy'
+ cmd = firewallpolicy.FirewallPolicyRemoveRule(
+ test_cli20.MyApp(sys.stdout),
+ None)
+ myid = 'myid'
+ args = ['myid', 'removerule']
+ extrafields = {'firewall_rule_id': 'removerule', }
+
+ self.mox.StubOutWithMock(cmd, "get_client")
+ self.mox.StubOutWithMock(self.client.httpclient, "request")
+ cmd.get_client().MultipleTimes().AndReturn(self.client)
+ body = extrafields
+ path = getattr(self.client, resource + "_remove_path")
+ self.client.httpclient.request(
+ test_cli20.MyUrlComparator(
+ test_cli20.end_url(path % myid, format=self.format),
+ self.client),
+ 'PUT', body=test_cli20.MyComparator(body, self.client),
+ headers=mox.ContainsKeyValue(
+ 'X-Auth-Token',
+ test_cli20.TOKEN)).AndReturn((test_cli20.MyResp(204), None))
+ args.extend(['--request-format', self.format])
+ self.mox.ReplayAll()
+ cmd_parser = cmd.get_parser(resource + "_remove_rule")
+ shell.run_command(cmd, cmd_parser, args)
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+
+
+class CLITestV20FirewallPolicyXML(CLITestV20FirewallPolicyJSON):
+ format = 'xml'
diff --git a/tests/unit/fw/test_cli20_firewallrule.py b/tests/unit/fw/test_cli20_firewallrule.py
new file mode 100644
index 0000000..18dd0e3
--- /dev/null
+++ b/tests/unit/fw/test_cli20_firewallrule.py
@@ -0,0 +1,158 @@
+# Copyright 2013 Big Switch Networks Inc.
+# All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# @author: KC Wang, Big Switch Networks Inc.
+#
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+import sys
+
+from neutronclient.neutron.v2_0.fw import firewallrule
+from tests.unit import test_cli20
+
+
+class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
+
+ def test_create_firewall_rule_with_mandatory_params(self):
+ """firewall-rule-create with mandatory (none) params only."""
+ resource = 'firewall_rule'
+ cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ tenant_id = 'my-tenant'
+ name = ''
+ my_id = 'myid'
+ protocol = 'tcp'
+ action = 'allow'
+ args = ['--tenant-id', tenant_id,
+ '--admin-state-up',
+ '--protocol', protocol,
+ '--action', action,
+ '--enabled']
+ position_names = []
+ position_values = []
+ self._test_create_resource(resource, cmd, name, my_id, args,
+ position_names, position_values,
+ protocol=protocol, action=action,
+ enabled=True, tenant_id=tenant_id)
+
+ def test_create_firewall_rule_with_all_params(self):
+ """firewall-rule-create with all params set."""
+ resource = 'firewall_rule'
+ cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ name = 'my-name'
+ description = 'my-desc'
+ protocol = 'tcp'
+ source_ip = '192.168.1.0/24'
+ destination_ip = '192.168.2.0/24'
+ source_port = '0:65535'
+ destination_port = '0:65535'
+ action = 'allow'
+ tenant_id = 'my-tenant'
+ my_id = 'myid'
+ args = ['--description', description,
+ '--shared',
+ '--protocol', protocol,
+ '--source-ip-address', source_ip,
+ '--destination-ip-address', destination_ip,
+ '--source-port', source_port,
+ '--destination-port', destination_port,
+ '--action', action,
+ '--enabled',
+ '--admin-state-up',
+ '--tenant-id', tenant_id]
+ position_names = []
+ position_values = []
+ self._test_create_resource(resource, cmd, name, my_id, args,
+ position_names, position_values,
+ description=description, shared=True,
+ protocol=protocol,
+ source_ip_address=source_ip,
+ destination_ip_address=destination_ip,
+ source_port=source_port,
+ destination_port=destination_port,
+ action=action, enabled=True,
+ tenant_id=tenant_id)
+
+ def test_list_firewall_rules(self):
+ """firewall-rule-list."""
+ resources = "firewall_rules"
+ cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources(resources, cmd, True)
+
+ def test_list_firewall_rules_pagination(self):
+ """firewall-rule-list."""
+ resources = "firewall_rules"
+ cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources_with_pagination(resources, cmd)
+
+ def test_list_firewall_rules_sort(self):
+ """firewall-rule-list --sort-key name --sort-key id --sort-key asc
+ --sort-key desc
+ """
+ resources = "firewall_rules"
+ cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources(resources, cmd,
+ sort_key=["name", "id"],
+ sort_dir=["asc", "desc"])
+
+ def test_list_firewall_rules_limit(self):
+ """firewall-rule-list -P."""
+ resources = "firewall_rules"
+ cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_list_resources(resources, cmd, page_size=1000)
+
+ def test_show_firewall_rule_id(self):
+ """firewall-rule-show test_id."""
+ resource = 'firewall_rule'
+ cmd = firewallrule.ShowFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ args = ['--fields', 'id', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
+
+ def test_show_firewall_rule_id_name(self):
+ """firewall-rule-show."""
+ resource = 'firewall_rule'
+ cmd = firewallrule.ShowFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ args = ['--fields', 'id', '--fields', 'name', self.test_id]
+ self._test_show_resource(resource, cmd, self.test_id,
+ args, ['id', 'name'])
+
+ def test_update_firewall_rule(self):
+ """firewall-rule-update myid --name newname."""
+ resource = 'firewall_rule'
+ cmd = firewallrule.UpdateFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ self._test_update_resource(resource, cmd, 'myid',
+ ['myid', '--name', 'newname'],
+ {'name': 'newname', })
+
+ def test_delete_firewall_rule(self):
+ """firewall-rule-delete my-id."""
+ resource = 'firewall_rule'
+ cmd = firewallrule.DeleteFirewallRule(test_cli20.MyApp(sys.stdout),
+ None)
+ my_id = 'myid1'
+ args = [my_id]
+ self._test_delete_resource(resource, cmd, my_id, args)
+
+
+class CLITestV20FirewallRuleXML(CLITestV20FirewallRuleJSON):
+ format = 'xml'
diff --git a/tests/unit/test_cli20.py b/tests/unit/test_cli20.py
index 52fdd60..b94ae8f 100644
--- a/tests/unit/test_cli20.py
+++ b/tests/unit/test_cli20.py
@@ -22,10 +22,10 @@ import mox
import testtools
from neutronclient.common import constants
+from neutronclient.neutron import v2_0 as neutronV2_0
from neutronclient import shell
from neutronclient.v2_0 import client
-
API_VERSION = "2.0"
FORMAT = 'json'
TOKEN = 'testtoken'
@@ -211,7 +211,9 @@ class CLITestV20Base(testtools.TestCase):
self.client.format = self.format
resstr = self.client.serialize(ress)
# url method body
- path = getattr(self.client, resource + "s_path")
+ resource_plural = neutronV2_0._get_resource_plural(resource,
+ self.client)
+ path = getattr(self.client, resource_plural + "_path")
self.client.httpclient.request(
end_url(path, format=self.format), 'POST',
body=MyComparator(body, self.client),