Skip to content

Commit

Permalink
fixes #13
Browse files Browse the repository at this point in the history
This commit will change the conf loading to always add the default localhost
connection profile.  This commit includes unit tests to validate that the
localhost connection is indeed present
  • Loading branch information
Peter Sprygada committed May 3, 2015
1 parent 6f995fc commit d0fa10c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Python Client for eAPI
## v0.3.0, IN PROGRESS

- fixes an issue with configuring stp portfast edge correctly
- fixes #13
- added initial support for system api module
- added initial support for acl api module (standard)
- added initial api support for mlag configuration
Expand Down
14 changes: 12 additions & 2 deletions pyeapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def autoload(self):
self.filename = filename
return self.read(filename)

self._add_default_connection()

def read(self, filename):
"""Reads the file specified by filename
Expand All @@ -181,8 +183,7 @@ def read(self, filename):
"""
SafeConfigParser.read(self, filename)

if not self.get_connection('localhost'):
self.add_connection('localhost', transport='socket')
self._add_default_connection()

for name in self.sections():
if name.startswith('connection:') and \
Expand All @@ -191,6 +192,15 @@ def read(self, filename):
self.set(name, 'host', name.split(':')[1])
self.generate_tags()

def _add_default_connection(self):
"""Checks the loaded config and adds the localhost profile if needed
This method wil load the connection:localhost profile into the client
configuration if it is not already present.
"""
if not self.get_connection('localhost'):
self.add_connection('localhost', transport='socket')

def generate_tags(self):
""" Generates the tags with collection with hosts
"""
Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def test_load_config(self):
name = 'connection:%s' % name
self.assertIn(name, pyeapi.client.config.sections())

def test_config_always_has_default_connection(self):
conf = '/invalid.conf'
pyeapi.client.load_config(conf)
self.assertEqual(len(pyeapi.client.config.sections()), 1)
name = 'connection:localhost'
self.assertIn(name, pyeapi.client.config.sections())

def test_connections_property(self):
conf = get_fixture('eapi.conf')
pyeapi.client.load_config(conf)
Expand Down

0 comments on commit d0fa10c

Please sign in to comment.