Skip to content

Commit b17fead

Browse files
committed
wip
1 parent f1aba4d commit b17fead

8 files changed

Lines changed: 53 additions & 47 deletions

File tree

f5/bigip/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ def hostname(self):
7171
def icontrol_version(self):
7272
return self._meta_data['icontrol_version']
7373

74-
@property
75-
def tmos_version(self):
76-
return self._meta_data['tmos_version']
77-
7874
def _get_tmos_version(self):
7975
connect = self._meta_data['bigip']._meta_data['icr_session']
8076
base_uri = self._meta_data['uri'] + 'tm/sys/'

f5/bigip/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __getattr__(container, name):
114114
return attribute
115115

116116
def _check_supported_versions(self, container, attribute):
117-
tmos_v = container._meta_data['bigip'].tmos_version
117+
tmos_v = container._meta_data['bigip']._meta_data['tmos_version']
118118
minimum = attribute._meta_data['minimum_version']
119119
if LooseVersion(tmos_v) < LooseVersion(minimum):
120120
error = "There was an attempt to access resource: \n{}\n which " \

f5/bigip/resource.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def __init__(self, container):
217217
self._set_meta_data_uri()
218218
# Supported versions for each class will be defined here.
219219
# List can be modified downstream in each sub-class
220+
print('about to set the "minimum_version" for %s' % self.__class__.__name__)
220221
self._meta_data['minimum_version'] = '11.5.0'
221222
# Commands you can run on a resource or collection, we define it here
222223
self._meta_data['allowed_commands'] = []
@@ -364,22 +365,6 @@ class ResourceBase(PathElement, ToDictMixin):
364365
that represents objects in a hierarchical relationship similar to the
365366
device's uri path hierarchy.
366367
"""
367-
def __init__(self, container):
368-
"""Call this with containing_object_instance.FOO
369-
370-
Where FOO is a concrete subclass of this class, ResourceBase. The '.'
371-
operator passes "FOO" to the __getattr__ method of the
372-
containing_object_instance which instantiates it as the appropriate
373-
sub-type of ResourceBase.
374-
375-
Since all ResourceBases sub-types must support the `refresh` method, it
376-
is defined here, in the base class.
377-
NOTE: The BIG-IP® uri 'mgmt/tm/' uniquely passes itself to this
378-
constructor as the "container".
379-
380-
:param container: instance is an attribute of a ResourceBase container
381-
"""
382-
super(ResourceBase, self).__init__(container)
383368

384369
def _modify(self, **patch):
385370
"""Wrapped with modify, override in a subclass to customize."""
@@ -634,12 +619,6 @@ class OrganizingCollection(ResourceBase):
634619
* provide a list of dictionaries that contain uri's to other
635620
resources on the device.
636621
"""
637-
def __init__(self, container):
638-
"""Call this to construct an OC. It should be an attribute of BIG-IP®.
639-
640-
:param bigip: all OCs are attributes of a BIG-IP® instance
641-
"""
642-
super(OrganizingCollection, self).__init__(container)
643622

644623
def get_collection(self, **kwargs):
645624
"""Call to obtain a list of the reference dicts in the instance `items`
@@ -665,20 +644,6 @@ class Collection(ResourceBase):
665644
unless it ends in ``s`` then it must have ``_s``.
666645
667646
"""
668-
def __init__(self, container):
669-
"""Call this with the __get_attr__ of a Resource or OC.
670-
671-
The contained-by-an-OC-or-Resource pattern is observed, and not a
672-
strictly enforced part of the model.
673-
674-
URIs are constructed _from_ Collection subclass names. All Collection
675-
subclass names MUST end in 's' or '_s', to distinguish them from their
676-
associated Resource (which is always accessible as an attribute of the
677-
subclass instance.
678-
679-
:param container: instances of Collection are attributes of container
680-
"""
681-
super(Collection, self).__init__(container)
682647

683648
def get_collection(self, **kwargs):
684649
"""Get an iterator of Python ``Resource`` objects that represent URIs.

f5/bigip/test/test_resource.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import mock
16+
from pprint import pprint as pp
1617
import pytest
1718
import requests
1819

@@ -39,6 +40,7 @@
3940
from f5.bigip.resource import UnregisteredKind
4041
from f5.bigip.resource import URICreationCollision
4142
from f5.bigip.tm.cm.sync_status import Sync_Status
43+
from f5.bigip.tm.ltm.virtual import Profiles_s
4244
from f5.bigip.tm.ltm.virtual import Virtual
4345
from f5.sdk_exception import UnsupportedMethod
4446

@@ -100,8 +102,8 @@ def test_Resource__local_update_IncompatibleKeys():
100102
" it's not a valid Python 2.7 identifier."
101103

102104

103-
def test_Resource__local_update():
104-
r = Resource(mock.MagicMock())
105+
def test_Resource__local_update(fake_vs):
106+
r = fake_vs
105107
stash = r._meta_data.copy()
106108
r._local_update({'test': 1})
107109
assert stash == r._meta_data
@@ -758,3 +760,46 @@ def test_load(self):
758760
r.generation = 0
759761
x = r.load(partition='Common', name='test_load')
760762
assert x.selfLink == 'https://localhost:443/mgmt/tm/cm/sync-status'
763+
764+
765+
class TestStats(object):
766+
def test_create_raises(self):
767+
stats_resource = Stats(mock.MagicMock())
768+
with pytest.raises(UnsupportedMethod):
769+
stats_resource.create()
770+
771+
def test_delete_raises(self):
772+
stats_resource = Stats(mock.MagicMock())
773+
with pytest.raises(UnsupportedMethod):
774+
stats_resource.delete()
775+
776+
def test_modify_raises(self):
777+
stats_resource = Stats(mock.MagicMock())
778+
with pytest.raises(UnsupportedMethod):
779+
stats_resource.modify()
780+
781+
def test_load(self):
782+
r = Virtual(mock.MagicMock())
783+
r._meta_data['allowed_lazy_attributes'] = []
784+
mockuri = "https://localhost:443/mgmt/tm/ltm/virtual"
785+
attrs = {'get.return_value':
786+
MockResponse(
787+
{
788+
u"generation": 0,
789+
u"selfLink": mockuri,
790+
u"kind": u"tm:ltm:virtual:virtualstate"
791+
}
792+
)}
793+
mock_session = mock.MagicMock(**attrs)
794+
r._meta_data['bigip']._meta_data =\
795+
{'icr_session': mock_session,
796+
'hostname': 'TESTDOMAINNAME',
797+
'uri': 'https://TESTDOMAIN:443/mgmt/tm/',
798+
'tmos_version': '11.5.0',
799+
'minimum_version': '11.5.0'}
800+
r.generation = 0
801+
x = r.load(partition='Common', name='test_load')
802+
assert x.selfLink == 'https://localhost:443/mgmt/tm/ltm/virtual'
803+
assert x._meta_data['allowed_lazy_attributes'] == [Profiles_s, Stats]
804+
pp(x.raw)
805+
x.stats

f5/bigip/tm/sys/test/test_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
def fake_dbs():
2424
fake_sys = mock.MagicMock()
2525
dbs = Dbs(fake_sys)
26-
dbs._meta_data['bigip'].tmos_version = '11.6.0'
26+
dbs._meta_data['bigip']._meta_data = {'tmos_version': '11.6.0'}
2727
return dbs
2828

2929

f5/bigip/tm/sys/test/test_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
def FakeFolders():
2525
fake_sys = mock.MagicMock()
2626
folders = Folders(fake_sys)
27-
folders._meta_data['bigip'].tmos_version = '11.6.0'
27+
folders._meta_data['bigip']._meta_data = {'tmos_version': '11.6.0'}
2828
return folders
2929

3030

f5/bigip/tm/sys/test/test_performance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def FakePerformance():
2626
fake_sys = mock.MagicMock()
2727
performances = Performances(fake_sys)
28-
performances._meta_data['bigip'].tmos_version = '11.6.0'
28+
performances._meta_data['bigip']._meta_data = {'tmos_version': '11.6.0'}
2929
return performances
3030

3131

test/functional/tm/ltm/test_virtual.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_stats(self, request, mgmt_root, setup_device_snapshot):
9292
stats.modify(description='foo')
9393
assert USMEIO.value.message ==\
9494
"Stats does not support the modify method"
95-
95+
9696

9797
def test_profiles_CE(
9898
mgmt_root, opt_release, setup_device_snapshot

0 commit comments

Comments
 (0)