Skip to content

Commit

Permalink
remote host is updated after system switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Depoix committed Jun 22, 2017
1 parent 3256ec6 commit 79c225e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
19 changes: 19 additions & 0 deletions goto_cloud/migration_commander/cloud_commanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,28 @@ def _execute(self):
)
if bootstrap_interface:
self._cloud_manager.delete_nic(self._target.remote_host.cloud_metadata['id'], bootstrap_interface['id'])
self._update_remote_host()
else:
self._add_error('bootstrapping network interface could not be found')

def _update_remote_host(self):
source_remote_host = self._source.remote_host
old_remote_host = self._target.remote_host

self._target.remote_host = RemoteHost.objects.create(
address=self._target.blueprint['network_interfaces'][0]['ip'],
cloud_metadata=old_remote_host.cloud_metadata,
username=source_remote_host.username,
os=source_remote_host.os,
version=source_remote_host.version,
port=source_remote_host.port,
password=source_remote_host.password,
private_key=source_remote_host.private_key,
)

self._target.save()
old_remote_host.delete()


class ConfigureBootDeviceCommand(CloudCommand):
def _execute(self):
Expand Down
45 changes: 45 additions & 0 deletions goto_cloud/migration_commander/tests/test_cloud_commanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,51 @@ def test_execute(self, mocked_delete_nic):

mocked_delete_nic.assert_called_with(self.CLOUD_DATA['id'], self.BOOTSTRAP_INTERFACE_ID)

@patch('cloud_management.public.CloudManager.delete_nic', lambda *args, **kwargs: None)
def test_execute__remote_host_updated(self):
self._init_test_data()
cloud_metadata = self.source.target.remote_host.cloud_metadata
old_remote_host_id = self.source.target.remote_host.id

DeleteBootstrapNetworkInterfaceCommand(self.source).execute()

self.source.refresh_from_db()

self.assertEqual(
self.source.target.remote_host.address,
self.source.target.blueprint['network_interfaces'][0]['ip']
)
self.assertEqual(
self.source.target.remote_host.cloud_metadata,
cloud_metadata
)
self.assertEqual(
self.source.target.remote_host.username,
self.source.remote_host.username
)
self.assertEqual(
self.source.target.remote_host.os,
self.source.remote_host.os
)
self.assertEqual(
self.source.target.remote_host.version,
self.source.remote_host.version
)
self.assertEqual(
self.source.target.remote_host.port,
self.source.remote_host.port
)
self.assertEqual(
self.source.target.remote_host.password,
self.source.remote_host.password
)
self.assertEqual(
self.source.target.remote_host.private_key,
self.source.remote_host.private_key
)
self.assertFalse(RemoteHost.objects.filter(id=old_remote_host_id).exists())


def test_execute__no_bootstrapping_interface_found(self):
self._init_test_data()
self.source.target.remote_host.refresh_from_db()
Expand Down

0 comments on commit 79c225e

Please sign in to comment.