Skip to content

Commit

Permalink
[tests] Moved test_device_config_update
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Apr 14, 2019
1 parent bb49a48 commit 3575048
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
31 changes: 0 additions & 31 deletions openwisp_controller/connection/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,6 @@ def _get_device_params(self, org):
p['organization'] = org.pk
return p

def test_device_config_update(self):
org1 = self._create_org(name='org1')
cred = self._create_credentials_with_key(organization=org1, port=self.ssh_server.port)
device = self._create_device(organization=org1)
update_strategy = app_settings.UPDATE_STRATEGIES[0][0]
c = self._create_config(device=device)
dc = self._create_device_connection(device=device,
credentials=cred,
update_strategy=update_strategy)
self._create_device_ip(device=device,
address=self.ssh_server.host)
uid = self.ssh_server.users
config = json.dumps({
'interfaces': [
{
'name': 'eth0',
'type': 'ethernet',
'addresses': [
{
'family': 'ipv4',
'proto': 'dhcp'
}
]
}
]
})
c.config = config
dc.update_config()
self.ssh_server.client(*uid).exec_command('/etc/init.d/openwisp_config restart')
self.assertEqual(device.status, 'applied')

def _create_multitenancy_test_env(self):
org1 = self._create_org(name='test1org')
org2 = self._create_org(name='test2org')
Expand Down
37 changes: 37 additions & 0 deletions openwisp_controller/connection/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,40 @@ def test_auto_add_to_existing_device_on_edit(self):
d.refresh_from_db()
self.assertEqual(d.deviceconnection_set.count(), 1)
self.assertEqual(d.deviceconnection_set.first().credentials, c)

def test_device_config_update(self):
org1 = self._create_org(name='org1')
cred = self._create_credentials_with_key(organization=org1, port=self.ssh_server.port)
device = self._create_device(organization=org1)
update_strategy = app_settings.UPDATE_STRATEGIES[0][0]
c = self._create_config(device=device)
self._create_device_connection(device=device,
credentials=cred,
update_strategy=update_strategy)
self._create_device_ip(device=device,
address=self.ssh_server.host)
c.config = {
'interfaces': [
{
'name': 'eth0',
'type': 'ethernet',
'addresses': [
{
'family': 'ipv4',
'proto': 'dhcp'
}
]
}
]
}
# here you can start capturing standard output
# see how it's done here: https://github.com/ncouture/MockSSH/blob/master/tests/test_mock_cisco.py#L14-L20
c.full_clean()
c.save()
# at this point the update_config() method will be triggered
# you need to create a command in the mocked SSH server that
# just prints something like: mock-ssh-server: openwisp-config restarted
# so you can then do:
# self.assertIn('mock-ssh-server: openwisp-config restarted', sdout)
# if update_config() finishes successfully then status will be set to "applied"
self.assertEqual(device.status, 'applied')

0 comments on commit 3575048

Please sign in to comment.