예제 #1
0
 def test_update_status_started(self):
     """
     Update status while the server is started, without change on the OpenStack VM
     """
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_1_building.json')
     self.assertEqual(server.update_status(), server.STARTED)
     self.assertEqual(server.status, server.STARTED)
예제 #2
0
 def test_update_status_started(self):
     """
     Update status while the server is started, without change on the OpenStack VM
     """
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_1_building.json')
     self.assertIsInstance(server.update_status(), ServerStatus.Active)
     self.assertEqual(server.progress, ServerProgress.Running)
예제 #3
0
 def test_reboot_server_wrong_status(self):
     """
     Attempt to reboot a server while in a status that doesn't allow it
     """
     server = StartedOpenStackServerFactory()
     with self.assertRaises(ServerNotReady):
         server.reboot()
예제 #4
0
 def test_update_status_started(self):
     """
     Update status while the server is started, without change on the OpenStack VM
     """
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_1_building.json')
     self.assertEqual(server.update_status(), server.ACTIVE)
     self.assertEqual(server.progress, server.PROGRESS_RUNNING)
예제 #5
0
 def test_reboot_server_wrong_status(self):
     """
     Attempt to reboot a server while in a status that doesn't allow it
     """
     server = StartedOpenStackServerFactory()
     with self.assertRaises(WrongStateException):
         server.reboot()
예제 #6
0
 def test_terminate_started_server(self):
     """
     Terminate a server with a 'started' status
     """
     server = StartedOpenStackServerFactory()
     server.terminate()
     self.assertEqual(server.status, server.TERMINATED)
     server.os_server.delete.assert_called_once_with()
예제 #7
0
 def test_update_status_started_to_active(self, mock_is_port_open):
     """
     Update status while the server is started, when the VM becomes active
     """
     mock_is_port_open.return_value = False
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_2_active.json')
     self.assertEqual(server.update_status(), server.ACTIVE)
     self.assertEqual(server.status, server.ACTIVE)
예제 #8
0
 def test_update_status_started_to_active(self, mock_is_port_open):
     """
     Update status while the server is started, when the VM becomes active
     """
     mock_is_port_open.return_value = False
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_2_active.json')
     self.assertIsInstance(server.update_status(), ServerStatus.Active)
     self.assertEqual(server.status, ServerStatus.Active)
     self.assertEqual(server.progress, ServerProgress.Success)
예제 #9
0
 def test_terminate_started_server(self):
     """
     Terminate a server with a 'started' status
     """
     server = StartedOpenStackServerFactory()
     server.terminate()
     self.assertEqual(server.status, ServerStatus.Terminated)
     self.assertEqual(server.progress, ServerProgress.Success)
     server.os_server.delete.assert_called_once_with()
예제 #10
0
 def test_reboot_provisioned_server(self, mock_sleep):
     """
     Reboot a provisioned server
     """
     server = StartedOpenStackServerFactory(_status=ServerStatus.Provisioning.state_id)
     server.reboot()
     self.assertEqual(server.status, ServerStatus.Rebooting)
     server.os_server.reboot.assert_called_once_with(reboot_type='SOFT')
     mock_sleep.assert_called_once_with(30)
예제 #11
0
 def test_status_terminated(self):
     """
     Instance status should revert to 'empty' when all its servers are terminated
     """
     instance = OpenEdXInstanceFactory()
     server = StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, server.Status.Started)
     server._transition(server._status_to_terminated)
     self.assertIsNone(instance.status)
예제 #12
0
 def test_reboot_provisioned_server(self, mock_sleep):
     """
     Reboot a provisioned server
     """
     server = StartedOpenStackServerFactory(status=OpenStackServer.PROVISIONING)
     server.reboot()
     self.assertEqual(server.status, server.REBOOTING)
     server.os_server.reboot.assert_called_once_with(reboot_type='SOFT')
     mock_sleep.assert_called_once_with(30)
예제 #13
0
 def test_status_terminated(self):
     """
     Instance status should revert to 'empty' when all its servers are terminated
     """
     instance = OpenEdXInstanceFactory()
     server = StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, server.Status.Started)
     server._transition(server._status_to_terminated)
     self.assertIsNone(instance.status)
예제 #14
0
 def test_update_status_provisioned_to_rebooting(self):
     """
     Update status when the server is rebooted, after being provisioned
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         status=OpenStackServer.PROVISIONED)
     self.assertEqual(server.update_status(), server.PROVISIONED)
     self.assertEqual(server.update_status(rebooting=True), server.REBOOTING)
     self.assertEqual(server.status, server.REBOOTING)
예제 #15
0
 def test_update_status_booted_to_provisioned(self):
     """
     Update status while the server is booted, when the VM is provisioned
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         status=OpenStackServer.BOOTED)
     self.assertEqual(server.update_status(), server.BOOTED)
     self.assertEqual(server.update_status(provisioned=True), server.PROVISIONED)
     self.assertEqual(server.status, server.PROVISIONED)
예제 #16
0
 def test_status_terminated(self):
     """
     Instance status should revert to 'empty' when all its servers are terminated
     """
     instance = OpenEdXInstanceFactory()
     server = StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, instance.STARTED)
     server.status = 'terminated'
     server.save()
     self.assertEqual(instance.status, instance.EMPTY)
예제 #17
0
 def test_update_status_booted_to_error(self):
     """
     Update status while the server is booted, when the VM failed to be provisioned
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         status=OpenStackServer.BOOTED)
     self.assertEqual(server.update_status(), server.BOOTED)
     self.assertEqual(server.update_status(provisioning=True), server.PROVISIONING)
     self.assertEqual(server.update_status(provisioning=True, failed=True), server.PROVISIONING)
     self.assertEqual(server.progress, server.PROGRESS_FAILED)
예제 #18
0
 def test_status_multiple_servers(self):
     """
     Instance status should not allow multiple active servers
     """
     instance = OpenEdXInstanceFactory()
     StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, Server.Status.Started)
     self.assertEqual(instance.progress, Server.Progress.Running)
     StartedOpenStackServerFactory(instance=instance)
     with self.assertRaises(InconsistentInstanceState):
         instance.status  #pylint: disable=pointless-statement
예제 #19
0
 def test_status(self):
     """
     Instance status with one active server
     """
     instance = OpenEdXInstanceFactory()
     self.assertEqual(instance.status, instance.EMPTY)
     server = StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, instance.STARTED)
     server.status = server.BOOTED
     server.save()
     self.assertEqual(instance.status, instance.BOOTED)
예제 #20
0
 def test_update_status_rebooting_to_ready(self, mock_is_port_open):
     """
     Update status while the server is rebooting, when the server becomes ready (ssh accessible again)
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         status=OpenStackServer.REBOOTING)
     mock_is_port_open.return_value = False
     self.assertEqual(server.update_status(), server.REBOOTING)
     mock_is_port_open.return_value = True
     self.assertEqual(server.update_status(), server.READY)
     self.assertEqual(server.status, server.READY)
예제 #21
0
 def test_update_status_active_to_booted(self, mock_is_port_open):
     """
     Update status while the server is active, when the VM becomes booted
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         status=OpenStackServer.ACTIVE)
     mock_is_port_open.return_value = False
     self.assertEqual(server.update_status(), server.ACTIVE)
     mock_is_port_open.return_value = True
     self.assertEqual(server.update_status(), server.BOOTED)
     self.assertEqual(server.status, server.BOOTED)
예제 #22
0
 def test_update_status_rebooting_to_ready(self, mock_is_port_open):
     """
     Update status while the server is rebooting, when the server becomes ready (ssh accessible again)
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         _status=ServerStatus.Rebooting.state_id)
     mock_is_port_open.return_value = False
     self.assertIsInstance(server.update_status(), ServerStatus.Rebooting)
     mock_is_port_open.return_value = True
     self.assertIsInstance(server.update_status(), ServerStatus.Ready)
     self.assertEqual(server.status, ServerStatus.Ready)
     self.assertEqual(server.progress, ServerProgress.Success)
예제 #23
0
 def test_update_status_active_to_booted(self, mock_is_port_open):
     """
     Update status while the server is active, when the VM becomes booted
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         _status=ServerStatus.Active.state_id)
     mock_is_port_open.return_value = False
     self.assertIsInstance(server.update_status(), ServerStatus.Active)
     mock_is_port_open.return_value = True
     self.assertIsInstance(server.update_status(), ServerStatus.Booted)
     self.assertEqual(server.status, ServerStatus.Booted)
     self.assertEqual(server.progress, ServerProgress.Success)
예제 #24
0
    def test_terminate_server_not_found(self):
        """
        Terminate a server for which the corresponding VM doesn't exist anymore
        """
        server = StartedOpenStackServerFactory()

        def raise_not_found(): #pylint: disable=missing-docstring
            raise novaclient.exceptions.NotFound('not-found')
        server.os_server.delete.side_effect = raise_not_found
        server.log = Mock()

        server.terminate()
        server.log.assert_any_call('exception', AnyStringMatching('Error while attempting to terminate server'))
        self.assertEqual(server.status, server.TERMINATED)
예제 #25
0
 def test_status(self):
     """
     Instance status with one active server
     """
     instance = OpenEdXInstanceFactory()
     self.assertIsNone(instance.status)
     self.assertIsNone(instance.progress)
     server = StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, Server.Status.Started)
     self.assertEqual(instance.progress, Server.Progress.Running)
     server._transition(server._status_to_active)
     self.assertEqual(instance.status, Server.Status.Active)
     server._transition(server._status_to_booted)
     self.assertEqual(instance.status, Server.Status.Booted)
예제 #26
0
    def test_terminate_server_not_found(self):
        """
        Terminate a server for which the corresponding VM doesn't exist anymore
        """
        server = StartedOpenStackServerFactory()

        def raise_not_found(): #pylint: disable=missing-docstring
            raise novaclient.exceptions.NotFound('not-found')
        server.os_server.delete.side_effect = raise_not_found
        server.logger = Mock()
        mock_logger = server.logger

        server.terminate()
        mock_logger.error.assert_called_once_with(AnyStringMatching('Error while attempting to terminate server'))
        self.assertEqual(server.status, ServerStatus.Terminated)
        self.assertEqual(server.progress, ServerProgress.Success)
예제 #27
0
    def test_inventory_str(self, os_server_manager):
        """
        Ansible inventory - showing servers once they are in booted status
        """
        instance = OpenEdXInstanceFactory()
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 1: 'started'
        StartedOpenStackServerFactory(instance=instance)
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 2: 'booted'
        server2 = BootedOpenStackServerFactory(instance=instance)
        os_server_manager.add_fixture(server2.openstack_id,
                                      'openstack/api_server_2_active.json')
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 3: 'provisioning'
        server3 = ProvisioningOpenStackServerFactory(instance=instance)
        os_server_manager.add_fixture(server3.openstack_id,
                                      'openstack/api_server_2_active.json')
        self.assertEqual(instance.inventory_str, '[app]\n192.168.100.200')

        # Server 4: 'provisioning'
        server4 = ProvisioningOpenStackServerFactory(instance=instance)
        os_server_manager.add_fixture(server4.openstack_id,
                                      'openstack/api_server_3_active.json')
        self.assertEqual(instance.inventory_str,
                         '[app]\n192.168.100.200\n192.168.99.66')
예제 #28
0
 def test_update_status_booted_to_error(self):
     """
     Update status while the server is booted, when the VM failed to be provisioned
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         _status=ServerStatus.Booted.state_id)
     self.assertIsInstance(server.update_status(), ServerStatus.Booted)
     server.mark_as_provisioning()
     self.assertEqual(server.status, ServerStatus.Provisioning)
     self.assertEqual(server.progress, ServerProgress.Running)
     server.mark_provisioning_finished(success=False)
     self.assertEqual(server.status, ServerStatus.Provisioning)
     self.assertEqual(server.progress, ServerProgress.Failed)
예제 #29
0
 def test_status(self):
     """
     Instance status with one active server
     """
     instance = OpenEdXInstanceFactory()
     self.assertIsNone(instance.status)
     self.assertIsNone(instance.progress)
     server = StartedOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.status, Server.Status.Started)
     self.assertEqual(instance.progress, Server.Progress.Running)
     server._transition(server._status_to_active)
     self.assertEqual(instance.status, Server.Status.Active)
     server._transition(server._status_to_booted)
     self.assertEqual(instance.status, Server.Status.Booted)
예제 #30
0
 def test_update_status_provisioned_to_rebooting(self, _mock_sleep, mock_is_port_open):
     """
     Update status when the server is rebooted, after being provisioned
     """
     server = StartedOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json',
         _status=ServerStatus.Provisioning.state_id,
         _progress=ServerProgress.Success.state_id)
     # If server is in Status.Rebooting, update_status calls is_port_open
     # to determine if server should transition to Status.Ready.
     # When using a fixture for server.os_server, is_port_open will eventually return False,
     # but only after a delay of about two minutes.
     # So we mock out is_port_open here to speed up testing:
     mock_is_port_open.return_value = False
     self.assertIsInstance(server.update_status(), ServerStatus.Provisioning)
     self.assertEqual(server.progress, ServerProgress.Success)
     server.reboot()
     self.assertEqual(server.status, ServerStatus.Rebooting)
     self.assertIsInstance(server.update_status(), ServerStatus.Rebooting)
     self.assertEqual(server.status, ServerStatus.Rebooting)
     self.assertEqual(server.progress, ServerProgress.Running)
예제 #31
0
 def test_public_ip_active_server(self):
     """
     Get the public IP of an active server
     """
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_2_active.json')
     self.assertEqual(server.public_ip, '192.168.100.200')
예제 #32
0
 def test_public_ip_started_server(self):
     """
     A server in `started` status doesn't have a public IP
     """
     server = StartedOpenStackServerFactory(os_server_fixture='openstack/api_server_1_building.json')
     self.assertEqual(server.public_ip, None)