Skip to content

Commit

Permalink
Merge 5ed288b into efaf42e
Browse files Browse the repository at this point in the history
  • Loading branch information
szymi- committed Jun 29, 2020
2 parents efaf42e + 5ed288b commit 3477299
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ python:
- "3.6"

before_install:
- nvm install 11.15.0
- nvm use 11.15.0
- pip install flake8==3.0.4 isort==4.2.5
- make flake
Expand Down
20 changes: 9 additions & 11 deletions src/ralph/networks/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ def update_dns_record(instance, created, *args, **kwargs):
if not _should_send_dnsaas_request(instance):
return
keys = ['address', 'hostname']
data_to_send = {
'old': {
key: instance._previous_state[key] for key in keys
},
'new': {
key: instance.__dict__[key] for key in keys
},
'service_uid': _get_connected_service_uid(instance)
}
data_to_send['action'] = 'add' if created else 'update'
if data_to_send['old']['hostname'] is not None:
old = {key: instance._previous_state[key] for key in keys}
new = {key: instance.__dict__[key] for key in keys}
if old != new and old['hostname'] is not None:
data_to_send = {
'old': old,
'new': new,
'service_uid': _get_connected_service_uid(instance),
'action': 'add' if created else 'update'
}
DNSaaS().send_ipaddress_data(data_to_send)


Expand Down
7 changes: 7 additions & 0 deletions src/ralph/networks/tests/test_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ def setUp(self):
address=self.dc_asset_ip.address
)

@patch('ralph.networks.receivers.DNSaaS')
def test_should_not_send_event_to_dnsaas_when_nothing_is_changed(self, dnsaas_mock):
update_dns_record(self.dc_asset_ip, False)
dnsaas_mock.assert_not_called()
dnsaas_mock().send_ipaddress_data.assert_not_called()

@patch('ralph.networks.receivers.DNSaaS')
def test_should_not_send_event_to_dnsaas_when_cloud_host(self, dnsaas_mock):
self.dc_asset_ip.hostname = 'myhost.mydc.net'
update_dns_record(self.cloud_ip, False)
dnsaas_mock.assert_not_called()
dnsaas_mock().send_ipaddress_data.assert_not_called()
Expand Down

0 comments on commit 3477299

Please sign in to comment.