Skip to content

Commit

Permalink
Issues: (#1335)
Browse files Browse the repository at this point in the history
Fixes #1334

Problem: Many old tests still reference the bigip object.

Analysis: Refactored all functional tests that use the bigip object to use the mgmt_root object instead
  • Loading branch information
f5-rahm authored and caphrim007 committed Dec 4, 2017
1 parent 037d244 commit 5c9af31
Show file tree
Hide file tree
Showing 35 changed files with 751 additions and 754 deletions.
14 changes: 6 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ def USER(bigip):
return n


def _delete_pools_members(bigip, pool_records):
def _delete_pools_members(mgmt_root, pool_records):
for pr in pool_records:
if bigip.ltm.pools.pool.exists(partition=pr.partition, name=pr.name):
pool_inst = bigip.ltm.pools.pool.load(partition=pr.partition,
name=pr.name)
if mgmt_root.tm.ltm.pools.pool.exists(partition=pr.partition, name=pr.name):
pool_inst = mgmt_root.tm.ltm.pools.pool.load(partition=pr.partition, name=pr.name)
members_list = pool_inst.members_s.get_collection()
pool_inst.delete()
for mem_inst in members_list:
Expand All @@ -201,14 +200,13 @@ def _delete_pools_members(bigip, pool_records):

@pytest.fixture
def pool_factory():
def _setup_boilerplate(bigip, request, pool_records):
_delete_pools_members(bigip, pool_records)
def _setup_boilerplate(mgmt_root, request, pool_records):
_delete_pools_members(mgmt_root, pool_records)
pool_registry = {}
members_registry = {}
for pr in pool_records:
pool_registry[pr.name] =\
bigip.ltm.pools.pool.create(partition=pr.partition,
name=pr.name)
mgmt_root.tm.ltm.pools.pool.create(partition=pr.partition, name=pr.name)
if pr.memberconfigs != (tuple(),):
members_collection = pool_registry[pr.name].members_s
for memconf in pr.memberconfigs:
Expand Down
8 changes: 4 additions & 4 deletions f5/bigip/shared/test/functional/test_bigip_failover_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
@pytest.mark.skipif(pytest.config.getoption('--release') != '12.0.0',
reason='Needs v12 TMOS to pass')
class TestBigIPFailoverState(object):
def test_load(self, request, bigip):
a = bigip.shared.bigip_failover_state.load()
def test_load(self, request, mgmt_root):
a = mgmt_root.shared.bigip_failover_state.load()
assert hasattr(a, 'generation')

def test_update(self, request, bigip):
def test_update(self, request, mgmt_root):
with pytest.raises(UnsupportedMethod):
bigip.shared.bigip_failover_state.update()
mgmt_root.shared.bigip_failover_state.update()
16 changes: 8 additions & 8 deletions f5/bigip/shared/test/functional/test_licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@


class TestActivation(object):
def test_load(self, request, bigip):
a = bigip.shared.licensing.activation.load()
def test_load(self, request, mgmt_root):
a = mgmt_root.tm.shared.licensing.activation.load()
assert hasattr(a, 'generation')

def test_update(self, request, bigip):
def test_update(self, request, mgmt_root):
with pytest.raises(UnsupportedMethod):
bigip.shared.licensing.activation.update()
mgmt_root.tm.shared.licensing.activation.update()


class TestRegistration(object):
def test_load(self, request, bigip):
reg = bigip.shared.licensing.registration.load()
def test_load(self, request, mgmt_root):
reg = mgmt_root.tm.shared.licensing.registration.load()
assert hasattr(reg, 'generation')

def test_update(self, request, bigip):
def test_update(self, request, mgmt_root):
with pytest.raises(UnsupportedMethod):
bigip.shared.licensing.registration.update()
mgmt_root.tm.shared.licensing.registration.update()
18 changes: 9 additions & 9 deletions f5/bigip/test/functional/test_requests_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
MemberConfig = namedtuple('MemberConfig', 'mempartition memname')


def test_get_collection(request, bigip, pool_factory, opt_release):
def test_get_collection(request, mgmt_root, pool_factory, opt_release):
Pool1MemberConfigs = (MemberConfig('Common', '192.168.15.15:80'),
MemberConfig('Common', '192.168.16.16:8080'),)
Pool1Config = PoolConfig('Common', 'TEST', Pool1MemberConfigs)
test_pools = (Pool1Config,)
pool_registry, member_registry =\
pool_factory(bigip, request, test_pools)
pool_factory(mgmt_root, request, test_pools)
selfLinks = []
for pool_inst in list(itervalues(pool_registry)):
for mem in pool_inst.members_s.get_collection():
Expand All @@ -39,23 +39,23 @@ def test_get_collection(request, bigip, pool_factory, opt_release):
'?ver='+opt_release


def test_get_dollar_filtered_collection(request, bigip, pool_factory):
if bigip.sys.folders.folder.exists(name='za', partition=''):
bigip.sys.folders.folder.load(name='za', partition='')
def test_get_dollar_filtered_collection(request, mgmt_root, pool_factory):
if mgmt_root.tm.sys.folders.folder.exists(name='za', partition=''):
mgmt_root.tm.sys.folders.folder.load(name='za', partition='')
else:
bigip.sys.folders.folder.create(name='za', subPath='/')
mgmt_root.tm.sys.folders.folder.create(name='za', subPath='/')
Pool1Config = PoolConfig('Common', 'TEST', ((),))
Pool2Config = PoolConfig('za', 'TEST', ((),))
test_pools = (Pool1Config, Pool2Config)
pool_registry, member_registry =\
pool_factory(bigip, request, test_pools)
pool_factory(mgmt_root, request, test_pools)
rp = {'params': '$filter=partition+eq+za'}
pools_in_za = bigip.ltm.pools.get_collection(requests_params=rp)
pools_in_za = mgmt_root.tm.ltm.pools.get_collection(requests_params=rp)
muri = pools_in_za[0]._meta_data['uri']
assert muri.endswith('/mgmt/tm/ltm/pool/~za~TEST/')


def test_get_dollar_select_collection_properties(request, bigip, mgmt_root):
def test_get_dollar_select_collection_properties(request, mgmt_root):
http_profiles = mgmt_root.tm.ltm.profile.https
without_select = http_profiles.get_collection()
with_select = http_profiles.get_collection(
Expand Down
8 changes: 4 additions & 4 deletions f5/bigip/tm/auth/test/functional/test_password_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@


class TestPasswordPolicy(object):
def test_load(self, bigip):
password_policy = bigip.auth.password_policy.load()
def test_load(self, mgmt_root):
password_policy = mgmt_root.tm.auth.password_policy.load()
assert password_policy.maxLoginFailures == 0
password_policy.refresh()
assert password_policy.maxLoginFailures == 0

def test_update(self, bigip):
password_policy = bigip.auth.password_policy.load()
def test_update(self, mgmt_root):
password_policy = mgmt_root.tm.auth.password_policy.load()
password_policy.update(maxLoginFailures=10)
assert password_policy.maxLoginFailures == 10
password_policy.update(maxLoginFailures=0)
Expand Down
4 changes: 2 additions & 2 deletions f5/bigip/tm/cm/test/functional/test_sync_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@


class TestSyncStatus(object):
def test_get_status(self, request, bigip):
sync_status = bigip.cm.sync_status
def test_get_status(self, request, mgmt_root):
sync_status = mgmt_root.tm.cm.sync_status
assert sync_status._meta_data['uri'].endswith(
"/mgmt/tm/cm/sync-status/")
sync_status.refresh()
Expand Down
18 changes: 9 additions & 9 deletions f5/bigip/tm/cm/test/functional/test_traffic_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
TEST_DESCR = "TEST DESCRIPTION"


def setup_traffic_group_test(request, bigip, name, partition, **kwargs):
def setup_traffic_group_test(request, mgmt_root, name, partition, **kwargs):
def teardown():
try:
tg.delete()
except HTTPError as err:
if err.response.status_code is not 404:
raise
request.addfinalizer(teardown)
tg = bigip.cm.traffic_groups.traffic_group.create(
tg = mgmt_root.tm.cm.traffic_groups.traffic_group.create(
name=name, partition=partition, **kwargs)
return tg

Expand All @@ -40,29 +40,29 @@ class TestTrafficGroups(object):
) < LooseVersion('11.6.0'),
reason='Skip test if on a version below 11.6.0. The '
'mac attribute does not exist in 11.5.4.')
def test_device_list_11_6_and_greater(self, bigip):
groups = bigip.cm.traffic_groups.get_collection()
def test_device_list_11_6_and_greater(self, mgmt_root):
groups = mgmt_root.tm.cm.traffic_groups.get_collection()
assert len(groups)
assert groups[0].generation > 0
assert hasattr(groups[0], 'mac')

def test_device_list_alternative(self, bigip):
def test_device_list_alternative(self, mgmt_root):
'''An alternative to test above that works regardless of version.'''
groups = bigip.cm.traffic_groups.get_collection()
groups = mgmt_root.tm.cm.traffic_groups.get_collection()
assert len(groups)
assert groups[0].generation > 0
assert hasattr(groups[0], 'isFloating')


class TestDevice(object):
def test_device_CURDL(self, request, bigip):
def test_device_CURDL(self, request, mgmt_root):
# Create and Delete are done by setup/teardown
tg1 = setup_traffic_group_test(
request, bigip, 'test-tg', 'Common')
request, mgmt_root, 'test-tg', 'Common')
assert tg1.generation > 0

# Load
tg2 = bigip.cm.traffic_groups.traffic_group.load(
tg2 = mgmt_root.tm.cm.traffic_groups.traffic_group.load(
name=tg1.name, partition=tg1.partition)
assert tg1.generation == tg2.generation

Expand Down
34 changes: 17 additions & 17 deletions f5/bigip/tm/cm/test/functional/test_trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
import pytest


def set_trust(request, bigip, name, device, dev_name, usr, passwd):
dvcs = bigip.cm
def set_trust(request, mgmt_root, name, device, dev_name, usr, passwd):
dvcs = mgmt_root.tm.cm
trust = dvcs.add_to_trust.exec_cmd('run', name=name, device=device,
deviceName=dev_name, username=usr,
caDevice=True, password=passwd)
return trust


def unset_trust(request, bigip, name, dev_name):
dvcs = bigip.cm
def unset_trust(request, mgmt_root, name, dev_name):
dvcs = mgmt_root.tm.cm
reset = dvcs.remove_from_trust.exec_cmd('run', name=name,
deviceName=dev_name)
return reset


def check_sync(request, bigip):
sync_status = bigip.cm.sync_status
def check_sync(request, mgmt_root):
sync_status = mgmt_root.tm.cm.sync_status
sync_status.refresh()
des = \
(sync_status.entries['https://localhost/mgmt/tm/cm/sync-status/0']
Expand All @@ -44,8 +44,8 @@ def check_sync(request, bigip):
return des


def check_peer(request, bigip):
dvcs = bigip.cm.devices.get_collection()
def check_peer(request, mgmt_root):
dvcs = mgmt_root.tm.cm.devices.get_collection()
device = str(dvcs[0].managementIp)
devname = str(dvcs[0].hostname)
return device, devname
Expand All @@ -54,33 +54,33 @@ def check_peer(request, bigip):
@pytest.mark.skipif(pytest.config.getoption('--peer') == 'none',
reason='Needs peer defined to run')
class TestTrust(object):
def test_run(self, request, bigip, peer):
def test_run(self, request, mgmt_root, peer):
# Check sync state, assume standalone
assert check_sync(request, bigip) == "Standalone"
assert check_sync(request, mgmt_root) == "Standalone"
assert check_sync(request, peer) == "Standalone"

# Obtain peer information
device1, devicename1 = check_peer(request, peer)
device2, devicename2 = check_peer(request, bigip)
device2, devicename2 = check_peer(request, mgmt_root)

# Setup trust
set_trust(request, bigip, 'Root', device1,
set_trust(request, mgmt_root, 'Root', device1,
devicename1, 'admin', 'admin')

# Verify sync state assume disconnected
assert check_sync(request, bigip) == "Disconnected"
assert check_sync(request, mgmt_root) == "Disconnected"
assert check_sync(request, peer) == "Disconnected"

# Remove trust from both units
unset_trust(request, bigip, 'Root', devicename1)
unset_trust(request, mgmt_root, 'Root', devicename1)
unset_trust(request, peer, 'Root', devicename2)

# Verify devices sync state is Standalone
assert check_sync(request, bigip) == "Standalone"
assert check_sync(request, mgmt_root) == "Standalone"
assert check_sync(request, peer) == "Standalone"

def test_invalid_cmd_meta(self, request, bigip):
dvcs = bigip.cm
def test_invalid_cmd_meta(self, request, mgmt_root):
dvcs = mgmt_root.tm.cm
with pytest.raises(InvalidCommand):
dvcs.add_to_trust.exec_cmd('foo', name='fooname',
device='foodev',
Expand Down
Loading

0 comments on commit 5c9af31

Please sign in to comment.