Merge "Jsonify meter and meter rule functional tests"
This commit is contained in:
commit
fe3bbf63a8
openstackclient/tests/functional/network/v2
@ -13,7 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import re
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from openstackclient.tests.functional import base
|
from openstackclient.tests.functional import base
|
||||||
@ -27,37 +27,45 @@ class TestMeter(base.TestCase):
|
|||||||
# has its own needs and there are collisions when running
|
# has its own needs and there are collisions when running
|
||||||
# tests in parallel.
|
# tests in parallel.
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
# Set up some regex for matching below
|
|
||||||
cls.re_name = re.compile("name\s+\|\s+([^|]+?)\s+\|")
|
|
||||||
cls.re_shared = re.compile("shared\s+\|\s+(\S+)")
|
|
||||||
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
|
|
||||||
|
|
||||||
def test_meter_delete(self):
|
def test_meter_delete(self):
|
||||||
"""Test create, delete multiple"""
|
"""Test create, delete multiple"""
|
||||||
name1 = uuid.uuid4().hex
|
name1 = uuid.uuid4().hex
|
||||||
name2 = uuid.uuid4().hex
|
name2 = uuid.uuid4().hex
|
||||||
|
description = 'fakedescription'
|
||||||
raw_output = self.openstack(
|
json_output = json.loads(self.openstack(
|
||||||
'network meter create ' + name1,
|
'network meter create -f json ' + name1 + ' --description '
|
||||||
|
+ description)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
name1,
|
name1,
|
||||||
re.search(self.re_name, raw_output).group(1),
|
json_output.get('name'),
|
||||||
)
|
)
|
||||||
# Check if default shared values
|
# Check if default shared values
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'False',
|
False,
|
||||||
re.search(self.re_shared, raw_output).group(1)
|
json_output.get('shared')
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'fakedescription',
|
||||||
|
json_output.get('description')
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_output = self.openstack(
|
json_output_2 = json.loads(self.openstack(
|
||||||
'network meter create ' + name2,
|
'network meter create -f json ' + name2 + ' --description '
|
||||||
|
+ description)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
name2,
|
name2,
|
||||||
re.search(self.re_name, raw_output).group(1),
|
json_output_2.get('name'),
|
||||||
|
)
|
||||||
|
# Check if default shared values
|
||||||
|
self.assertEqual(
|
||||||
|
False,
|
||||||
|
json_output_2.get('shared')
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'fakedescription',
|
||||||
|
json_output_2.get('description')
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_output = self.openstack(
|
raw_output = self.openstack(
|
||||||
@ -68,35 +76,83 @@ class TestMeter(base.TestCase):
|
|||||||
def test_meter_list(self):
|
def test_meter_list(self):
|
||||||
"""Test create, list filters, delete"""
|
"""Test create, list filters, delete"""
|
||||||
name1 = uuid.uuid4().hex
|
name1 = uuid.uuid4().hex
|
||||||
raw_output = self.openstack(
|
json_output = json.loads(self.openstack(
|
||||||
'network meter create --description Test1 --share ' + name1,
|
'network meter create -f json --description Test1 --share '
|
||||||
|
+ name1)
|
||||||
)
|
)
|
||||||
self.addCleanup(self.openstack, 'network meter delete ' + name1)
|
self.addCleanup(self.openstack, 'network meter delete ' + name1)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'Test1',
|
'Test1',
|
||||||
re.search(self.re_description, raw_output).group(1),
|
json_output.get('description'),
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'True',
|
True,
|
||||||
re.search(self.re_shared, raw_output).group(1),
|
json_output.get('shared'),
|
||||||
)
|
)
|
||||||
|
|
||||||
name2 = uuid.uuid4().hex
|
name2 = uuid.uuid4().hex
|
||||||
raw_output = self.openstack(
|
json_output_2 = json.loads(self.openstack(
|
||||||
'network meter create --description Test2 --no-share ' + name2,
|
'network meter create -f json --description Test2 --no-share '
|
||||||
|
+ name2)
|
||||||
)
|
)
|
||||||
self.addCleanup(self.openstack, 'network meter delete ' + name2)
|
self.addCleanup(self.openstack, 'network meter delete ' + name2)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'Test2',
|
'Test2',
|
||||||
re.search(self.re_description, raw_output).group(1),
|
json_output_2.get('description')
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'False',
|
False,
|
||||||
re.search(self.re_shared, raw_output).group(1),
|
json_output_2.get('shared')
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_output = self.openstack('network meter list')
|
raw_output = json.loads(self.openstack('network meter list -f json'))
|
||||||
self.assertIsNotNone(re.search(name1 + "\s+\|\s+Test1", raw_output))
|
name_list = [item.get('Name') for item in raw_output]
|
||||||
self.assertIsNotNone(re.search(name2 + "\s+\|\s+Test2", raw_output))
|
self.assertIn(name1, name_list)
|
||||||
|
self.assertIn(name2, name_list)
|
||||||
|
|
||||||
|
def test_meter_show(self):
|
||||||
|
"""Test create, show, delete"""
|
||||||
|
name1 = uuid.uuid4().hex
|
||||||
|
description = 'fakedescription'
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'network meter create -f json ' + name1 + ' --description '
|
||||||
|
+ description)
|
||||||
|
)
|
||||||
|
meter_id = json_output.get('id')
|
||||||
|
self.addCleanup(self.openstack, 'network meter delete ' + name1)
|
||||||
|
|
||||||
|
# Test show with ID
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'network meter show -f json ' + meter_id)
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
False,
|
||||||
|
json_output.get('shared')
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'fakedescription',
|
||||||
|
json_output.get('description')
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
name1,
|
||||||
|
json_output.get('name')
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test show with name
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'network meter show -f json ' + name1)
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
meter_id,
|
||||||
|
json_output.get('id')
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
False,
|
||||||
|
json_output.get('shared')
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'fakedescription',
|
||||||
|
json_output.get('description')
|
||||||
|
)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import re
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from openstackclient.tests.functional import base
|
from openstackclient.tests.functional import base
|
||||||
@ -27,19 +27,11 @@ class TestMeterRule(base.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
# Set up some regex for matching below
|
json_output = json.loads(cls.openstack(
|
||||||
cls.re_id = re.compile("id\s+\|\s+(\S+)")
|
'network meter create -f json ' + cls.METER_NAME
|
||||||
cls.re_direction = re.compile("direction\s+\|\s+(\S+)")
|
))
|
||||||
cls.re_ip_prefix = re.compile(
|
|
||||||
"remote_ip_prefix\s+\|\s+([^|]+?)\s+\|"
|
|
||||||
)
|
|
||||||
cls.re_meter_id = re.compile("metering_label_id\s+\|\s+(\S+)")
|
|
||||||
|
|
||||||
raw_output = cls.openstack(
|
cls.METER_ID = json_output.get('id')
|
||||||
'network meter create ' + cls.METER_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
cls.METER_ID = re.search(cls.re_id, raw_output).group(1)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
@ -49,58 +41,81 @@ class TestMeterRule(base.TestCase):
|
|||||||
def test_meter_rule_delete(self):
|
def test_meter_rule_delete(self):
|
||||||
"""test create, delete"""
|
"""test create, delete"""
|
||||||
|
|
||||||
raw_output = self.openstack(
|
json_output = json.loads(self.openstack(
|
||||||
'network meter rule create ' +
|
'network meter rule create -f json ' +
|
||||||
'--remote-ip-prefix 10.0.0.0/8 ' +
|
'--remote-ip-prefix 10.0.0.0/8 ' +
|
||||||
self.METER_ID
|
self.METER_ID
|
||||||
)
|
))
|
||||||
rule_id = re.search(self.re_id, raw_output).group(1)
|
rule_id = json_output.get('id')
|
||||||
re_ip = re.search(self.re_ip_prefix, raw_output)
|
re_ip = json_output.get('remote_ip_prefix')
|
||||||
|
|
||||||
self.addCleanup(self.openstack,
|
self.addCleanup(self.openstack,
|
||||||
'network meter rule delete ' + rule_id)
|
'network meter rule delete ' + rule_id)
|
||||||
self.assertIsNotNone(re_ip)
|
self.assertIsNotNone(re_ip)
|
||||||
self.assertIsNotNone(rule_id)
|
self.assertIsNotNone(rule_id)
|
||||||
|
self.assertEqual(
|
||||||
|
'10.0.0.0/8', re_ip
|
||||||
|
)
|
||||||
|
|
||||||
def test_meter_rule_list(self):
|
def test_meter_rule_list(self):
|
||||||
"""Test create, list, delete"""
|
"""Test create, list, delete"""
|
||||||
raw_output = self.openstack(
|
json_output = json.loads(self.openstack(
|
||||||
'network meter rule create ' +
|
'network meter rule create -f json ' +
|
||||||
'--remote-ip-prefix 10.0.0.0/8 ' +
|
'--remote-ip-prefix 10.0.0.0/8 ' +
|
||||||
self.METER_ID
|
self.METER_ID
|
||||||
)
|
))
|
||||||
rule_id = re.search(self.re_id, raw_output).group(1)
|
rule_id_1 = json_output.get('id')
|
||||||
self.addCleanup(self.openstack,
|
self.addCleanup(self.openstack,
|
||||||
'network meter rule delete ' + rule_id)
|
'network meter rule delete ' + rule_id_1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'10.0.0.0/8',
|
'10.0.0.0/8',
|
||||||
re.search(self.re_ip_prefix, raw_output).group(1)
|
json_output.get('remote_ip_prefix')
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_output = self.openstack('network meter rule list')
|
json_output_1 = json.loads(self.openstack(
|
||||||
self.assertIsNotNone(re.search(rule_id + "|\s+\|\s+\|\s+10.0.0.0/8",
|
'network meter rule create -f json ' +
|
||||||
raw_output))
|
'--remote-ip-prefix 11.0.0.0/8 ' +
|
||||||
|
self.METER_ID
|
||||||
|
))
|
||||||
|
rule_id_2 = json_output_1.get('id')
|
||||||
|
self.addCleanup(self.openstack,
|
||||||
|
'network meter rule delete ' + rule_id_2)
|
||||||
|
self.assertEqual(
|
||||||
|
'11.0.0.0/8',
|
||||||
|
json_output_1.get('remote_ip_prefix')
|
||||||
|
)
|
||||||
|
|
||||||
|
json_output = json.loads(self.openstack('network meter rule list -f '
|
||||||
|
'json'))
|
||||||
|
rule_id_list = [item.get('ID') for item in json_output]
|
||||||
|
ip_prefix_list = [item.get('Remote IP Prefix') for item in json_output]
|
||||||
|
self.assertIn(rule_id_1, rule_id_list)
|
||||||
|
self.assertIn(rule_id_2, rule_id_list)
|
||||||
|
self.assertIn('10.0.0.0/8', ip_prefix_list)
|
||||||
|
self.assertIn('11.0.0.0/8', ip_prefix_list)
|
||||||
|
|
||||||
def test_meter_rule_show(self):
|
def test_meter_rule_show(self):
|
||||||
|
|
||||||
"""Test create, show, delete"""
|
"""Test create, show, delete"""
|
||||||
raw_output = self.openstack(
|
json_output = json.loads(self.openstack(
|
||||||
'network meter rule create ' +
|
'network meter rule create -f json ' +
|
||||||
'--remote-ip-prefix 10.0.0.0/8 ' +
|
'--remote-ip-prefix 10.0.0.0/8 ' +
|
||||||
'--egress ' +
|
'--egress ' +
|
||||||
self.METER_ID
|
self.METER_ID
|
||||||
)
|
))
|
||||||
rule_id = re.search(self.re_id, raw_output).group(1)
|
rule_id = json_output.get('id')
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'egress',
|
'egress',
|
||||||
re.search(self.re_direction, raw_output).group(1)
|
json_output.get('direction')
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_output = self.openstack('network meter rule show ' + rule_id)
|
json_output = json.loads(self.openstack('network meter rule show'
|
||||||
|
' -f json ' + rule_id))
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'10.0.0.0/8',
|
'10.0.0.0/8',
|
||||||
re.search(self.re_ip_prefix, raw_output).group(1)
|
json_output.get('remote_ip_prefix')
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(rule_id)
|
self.assertIsNotNone(rule_id)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user