Skip to content

Commit

Permalink
Fix subnet tests (#13284)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Talreja <[email protected]>
(cherry picked from commit 8416dde)
  • Loading branch information
Gauravtalreja1 authored and web-flow committed Dec 6, 2023
1 parent 5643a65 commit 5164e4c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/foreman/cli/test_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import random
import re

from fauxfactory import gen_choice, gen_integer, gen_ipaddr
from fauxfactory import gen_choice, gen_integer, gen_ipaddr, gen_netmask
import pytest

from robottelo.constants import SUBNET_IPAM_TYPES
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_positive_CRUD(module_target_sat):
"""
name = gen_choice(list(valid_data_list().values()))
pool = sorted(valid_addr_pools()[0])
mask = '255.255.255.0'
mask = gen_netmask()
# generate pool range from network address
network = gen_ipaddr()
from_ip = re.sub(r'\d+$', str(pool[0]), network)
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_positive_CRUD(module_target_sat):
pool = sorted(valid_addr_pools()[0])
# generate pool range from network address
new_network = gen_ipaddr()
new_mask = '255.255.192.0'
new_mask = gen_netmask()
ip_from = re.sub(r'\d+$', str(pool[0]), new_network)
ip_to = re.sub(r'\d+$', str(pool[1]), new_network)
ipam_type = SUBNET_IPAM_TYPES['internal']
Expand Down Expand Up @@ -180,20 +180,19 @@ def test_negative_create_with_address_pool(pool, module_target_sat):
:CaseImportance: Medium
"""
mask = '255.255.255.0'
mask = gen_netmask()
network = gen_ipaddr()
opts = {'mask': mask, 'network': network}
options = {'mask': mask, 'network': network}
# generate pool range from network address
for key, val in pool.items():
opts[key] = re.sub(r'\d+$', str(val), network)
with pytest.raises(CLIFactoryError) as raise_ctx:
module_target_sat.cli_factory.make_subnet(opts)
assert 'Could not create the subnet:' in str(raise_ctx.value)
options[key] = re.sub(r'\d+$', str(val), network)
with pytest.raises(CLIFactoryError, match='Could not create the subnet:'):
module_target_sat.cli_factory.make_subnet(options)


@pytest.mark.tier2
@pytest.mark.parametrize('options', **parametrized(invalid_missing_attributes()))
def test_negative_update_attributes(options, module_target_sat):
def test_negative_update_attributes(request, options, module_target_sat):
"""Update subnet with invalid or missing required attributes
:parametrized: yes
Expand All @@ -206,17 +205,18 @@ def test_negative_update_attributes(options, module_target_sat):
"""
subnet = module_target_sat.cli_factory.make_subnet()
options['id'] = subnet['id']
request.addfinalizer(lambda: module_target_sat.cli.Subnet.delete({'id': subnet['id']}))
with pytest.raises(CLIReturnCodeError, match='Could not update the subnet:'):
module_target_sat.cli.Subnet.update(options)
# check - subnet is not updated
result = module_target_sat.cli.Subnet.info({'id': subnet['id']})
for key in options.keys():
for key in ['name', 'network-addr', 'network-mask']:
assert subnet[key] == result[key]


@pytest.mark.tier2
@pytest.mark.parametrize('options', **parametrized(invalid_addr_pools()))
def test_negative_update_address_pool(options, module_target_sat):
def test_negative_update_address_pool(request, options, module_target_sat):
"""Update subnet with invalid address pool
:parametrized: yes
Expand All @@ -229,6 +229,7 @@ def test_negative_update_address_pool(options, module_target_sat):
"""
subnet = module_target_sat.cli_factory.make_subnet()
opts = {'id': subnet['id']}
request.addfinalizer(lambda: module_target_sat.cli.Subnet.delete({'id': subnet['id']}))
# generate pool range from network address
for key, val in options.items():
opts[key] = re.sub(r'\d+$', str(val), subnet['network-addr'])
Expand Down

0 comments on commit 5164e4c

Please sign in to comment.