Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
watcher: Update for secret models
Browse files Browse the repository at this point in the history
  • Loading branch information
ashcrow authored and mbarnes committed May 25, 2017
1 parent 8940609 commit 2ca7fdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/commissaire_service/watcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from time import sleep

from commissaire import constants as C
from commissaire.models import WatcherRecord
from commissaire.models import HostCreds, WatcherRecord
from commissaire.storage.client import StorageClient
from commissaire.util.date import formatted_dt
from commissaire.util.ssh import TemporarySSHKey
Expand Down Expand Up @@ -118,9 +118,11 @@ def _check(self, address):
self.logger.info('Checking host "{}".'.format(address))

host = self.storage.get_host(address)
transport = ansibleapi.Transport(host.remote_user)
host_creds = self.storage.get(HostCreds.new(address=host.address))

with TemporarySSHKey(host, self.logger) as key:
transport = ansibleapi.Transport(host_creds.remote_user)

with TemporarySSHKey(host_creds, self.logger) as key:
try:
self.logger.debug(
'Starting watcher run for host "{}"'.format(address))
Expand Down
2 changes: 2 additions & 0 deletions test/test_service_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def test__check_with_no_errors(self):
self.service_instance.storage.get_host.return_value = models.Host.new(
address='127.0.0.1',
last_check=datetime.datetime.min.isoformat())
self.service_instance.storage.get.return_value = models.HostCreds.new(
address='127.0.0.1')
self.service_instance.storage.save.return_value = None
self.service_instance._check('127.0.0.1')
# The transport method should have been called once
Expand Down

0 comments on commit 2ca7fdd

Please sign in to comment.