Skip to content

Commit

Permalink
"version 1.0.56"
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbalogh committed Aug 7, 2020
1 parent 30ccd1b commit 39f6340
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
5 changes: 5 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

### Aug 2020
* 1.0.56
* fixed intermittent KeyError: 'href' bug
* enhanced KeyError message when error is valid

### Jul 2020
* 1.0.55
* PortMapAssistant.Connect method bug fix
Expand Down
2 changes: 1 addition & 1 deletion ixnetwork_restpy/assistants/sessions/sessionassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, IpAddress='127.0.0.1', RestPort=11009, UserName='admin', Pass
if SessionId is not None:
session = testplatform.Sessions.find(Id=SessionId)
if len(session) == 0:
raise NotFoundError('Session %s does not exist on %s:%s', (SessionId, testplatform.Hostname, testplatform.RestPort))
raise NotFoundError('Session %s does not exist on %s:%s' % (SessionId, testplatform.Hostname, testplatform.RestPort))
session.Name = SessionName
elif SessionName is not None:
session = testplatform.Sessions.find(Name=SessionName)
Expand Down
36 changes: 29 additions & 7 deletions ixnetwork_restpy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def _get_attribute(self, name):
try:
return self._properties[name]
except Exception as e:
raise NotFoundError('The attribute %s is not in the internal list of object dicts. (%s)' % (name, e))
msg = """The attribute %s is not in the internal list of object dicts.
If there is a find method execute that prior to executing a property accessor.
Check the number of encapsulated resources using the len method.
%s
""" % (name, e)
raise NotFoundError(msg)

def _set_attribute(self, name, value):
"""Update a property on the server and save it locally if there is no exception
Expand All @@ -155,7 +160,7 @@ def __str__(self):
instances = ''
for i in range(len(self)):
properties = self._object_properties[i]
instances += '\n%s[%s]: %s' % (self.__class__.__name__, i, properties['href'])
instances += '\n%s[%s]: %s' % (self.__class__.__name__, i, self.href)
for key in sorted(properties.keys()):
if key == 'href':
continue
Expand Down Expand Up @@ -273,8 +278,7 @@ def _set_properties(self, properties, clear=False):
def _update(self, locals_dict):
payload = self._build_payload(locals_dict)
if payload is not None:
self._connection._update(self._properties['href'], payload)
return self.refresh()
self._connection._update(self.href, payload)
return self

def _delete(self):
Expand All @@ -287,7 +291,7 @@ def _delete(self):
raise e

def _execute(self, operation, child=None, payload=None, response_object=None):
url = self._properties['href']
url = self.href
if child is not None:
url = '%s/%s' % (url, child)
if operation is not None:
Expand Down Expand Up @@ -322,7 +326,7 @@ def refresh(self):
for properties in self._object_properties:
selects.append(
{
'from': properties['href'],
'from': self.href,
'properties': ['*'],
'children': [],
'inlines': []
Expand All @@ -346,6 +350,21 @@ def _read(self, href):
self._set_properties(response, clear=True)
return self

def __is_key_value_in_response(self, key_value, response):
"""Return whether or not a key is in a response
"""
if isinstance(response, list):
for item in response:
if self.__is_key_value_in_response(key_value, item) is True:
return True
elif isinstance(response, dict):
if key_value in response.keys():
return True
for value in response.values():
if self.__is_key_value_in_response(key_value, value) is True:
return True
return False

def _select(self, locals_dict=dict()):
selects = []
for parent in self._parent:
Expand Down Expand Up @@ -377,7 +396,10 @@ def _select(self, locals_dict=dict()):
if 'ixnetwork' in self._parent.href:
end = self._parent.href.index('ixnetwork') + len('ixnetwork')
url = '%s/operations/select' % self._parent.href[0:end]
responses = self._connection._execute(url, payload)
while True:
responses = self._connection._execute(url, payload)
if self.__is_key_value_in_response('objRef', responses) is False:
break
self._set_properties(None, clear=True)
# process children of from
for response in responses:
Expand Down
18 changes: 9 additions & 9 deletions ixnetwork_restpy/pytest_tests/tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from ixnetwork_restpy.errors import *


def test_operation_returns_400_error (ixnetwork):
def test_operation_improper_name (ixnetwork):
try:
ixnetwork.ConnectCardById('2323232')
raise Exception('Error should have been raised')
except Exception as e:
print(e)
ixnetwork.NewConfig1()
assert Exception('Error should have been raised')
except AttributeError as e:
pass

def test_operation_returns_404_error (ixnetwork):
try:
ixnetwork.ConnectCardById('2323232', 'asdf')
raise Exception('Error should have been raised')
except Exception as e:
print(e)
ixnetwork.LoadConfig('arg1', 'arg2', 'arg3')
assert Exception('Error should have been raised')
except NotFoundError as e:
pass
1 change: 0 additions & 1 deletion ixnetwork_restpy/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from ixnetwork_restpy.base import Base


class Select(object):
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.55
1.0.56

0 comments on commit 39f6340

Please sign in to comment.