Beispiel #1
0
    def test_status_transitions(self):
        """
        Test that status transitions work as expected for different server workflows
        """
        # Normal workflow
        server = OpenStackServerFactory()
        self.assertEqual(server.status, ServerStatus.Pending)
        self._assert_status_conditions(server)

        server._status_to_building()
        self.assertEqual(server.status, ServerStatus.Building)
        self._assert_status_conditions(server)

        server._status_to_booting()
        self.assertEqual(server.status, ServerStatus.Booting)
        self._assert_status_conditions(server, vm_available=True)

        server._status_to_ready()
        self.assertEqual(server.status, ServerStatus.Ready)
        self._assert_status_conditions(server, is_steady_state=True, accepts_ssh_commands=True, vm_available=True)

        server._status_to_terminated()
        self.assertEqual(server.status, ServerStatus.Terminated)
        self._assert_status_conditions(server, is_steady_state=True)

        # Server creation fails
        instance_bad_server = BuildingOpenStackServerFactory()
        instance_bad_server._status_to_build_failed()
        self.assertEqual(instance_bad_server.status, ServerStatus.BuildFailed)
        self._assert_status_conditions(server, is_steady_state=True)
Beispiel #2
0
    def test_status_transitions(self):
        """
        Test that status transitions work as expected for different server workflows
        """
        # Normal workflow
        server = OpenStackServerFactory()
        self.assertEqual(server.status, ServerStatus.Pending)
        self._assert_status_conditions(server)

        server._status_to_building()
        self.assertEqual(server.status, ServerStatus.Building)
        self._assert_status_conditions(server)

        server._status_to_unknown()
        self.assertEqual(server.status, ServerStatus.Unknown)
        self._assert_status_conditions(server)

        server._status_to_building()
        self.assertEqual(server.status, ServerStatus.Building)
        self._assert_status_conditions(server)

        server._status_to_booting()
        self.assertEqual(server.status, ServerStatus.Booting)
        self._assert_status_conditions(server, vm_available=True)

        server._status_to_unknown()
        self.assertEqual(server.status, ServerStatus.Unknown)
        self._assert_status_conditions(server)

        server._status_to_booting()
        self.assertEqual(server.status, ServerStatus.Booting)
        self._assert_status_conditions(server, vm_available=True)

        server._status_to_ready()
        self.assertEqual(server.status, ServerStatus.Ready)
        self._assert_status_conditions(server,
                                       is_steady_state=True,
                                       accepts_ssh_commands=True,
                                       vm_available=True)

        server._status_to_unknown()
        self.assertEqual(server.status, ServerStatus.Unknown)
        self._assert_status_conditions(server)

        server._status_to_ready()
        self.assertEqual(server.status, ServerStatus.Ready)
        self._assert_status_conditions(server,
                                       is_steady_state=True,
                                       accepts_ssh_commands=True,
                                       vm_available=True)

        server._status_to_terminated()
        self.assertEqual(server.status, ServerStatus.Terminated)
        self._assert_status_conditions(server, is_steady_state=True)

        # Server creation fails
        instance_bad_server = BuildingOpenStackServerFactory()
        instance_bad_server._status_to_build_failed()
        self.assertEqual(instance_bad_server.status, ServerStatus.BuildFailed)
        self._assert_status_conditions(server, is_steady_state=True)
Beispiel #3
0
 def test_update_status_building(self):
     """
     Update status while the server is building, without change on the OpenStack VM
     """
     server = BuildingOpenStackServerFactory(os_server_fixture='openstack/api_server_1_building.json')
     self.assertEqual(server.status, ServerStatus.Building)
     self.assertIsInstance(server.update_status(), ServerStatus.Building)
     self.assertEqual(server.status, ServerStatus.Building)
Beispiel #4
0
 def test_update_status_building(self):
     """
     Update status while the server is building, without change on the OpenStack VM
     """
     server = BuildingOpenStackServerFactory(os_server_fixture='openstack/api_server_1_building.json')
     self.assertEqual(server.status, ServerStatus.Building)
     self.assertIsInstance(server.update_status(), ServerStatus.Building)
     self.assertEqual(server.status, ServerStatus.Building)
Beispiel #5
0
 def test_server_status_terminated(self):
     """
     Server status of an instance should revert to 'empty' when all its servers are terminated
     """
     instance = SingleVMOpenEdXInstanceFactory()
     server = BuildingOpenStackServerFactory(instance=instance)
     self.assertEqual(instance.server_status, server.Status.Building)
     server._status_to_terminated()
     self.assertIsNone(instance.server_status)
Beispiel #6
0
 def test_update_status_building_to_booting(self, mock_is_port_open):
     """
     Update status while the server is building, when the VM becomes active
     """
     mock_is_port_open.return_value = False
     server = BuildingOpenStackServerFactory(os_server_fixture='openstack/api_server_2_active.json')
     self.assertEqual(server.status, ServerStatus.Building)
     self.assertIsInstance(server.update_status(), ServerStatus.Booting)
     self.assertEqual(server.status, ServerStatus.Booting)
Beispiel #7
0
 def test_update_status_building_to_booting(self, mock_is_port_open):
     """
     Update status while the server is building, when the VM becomes active
     """
     mock_is_port_open.return_value = False
     server = BuildingOpenStackServerFactory(os_server_fixture='openstack/api_server_2_active.json')
     self.assertEqual(server.status, ServerStatus.Building)
     self.assertIsInstance(server.update_status(), ServerStatus.Booting)
     self.assertEqual(server.status, ServerStatus.Booting)
Beispiel #8
0
 def test_public_ip_active_server(self):
     """
     Get the public IP of an active server
     """
     server = BuildingOpenStackServerFactory(
         os_server_fixture='openstack/api_server_2_active.json')
     self.assertEqual(server.public_ip, '192.168.100.200')
Beispiel #9
0
 def test_public_ip_building_server(self):
     """
     A server in 'building' status doesn't have a public IP
     """
     server = BuildingOpenStackServerFactory(
         os_server_fixture='openstack/api_server_1_building.json')
     self.assertEqual(server.public_ip, None)
Beispiel #10
0
 def test_server_status(self):
     """
     Server status of an instance with one active server
     """
     instance = SingleVMOpenEdXInstanceFactory()
     self.assertIsNone(instance.server_status)
     server = OpenStackServerFactory(instance=instance)
     self.assertEqual(instance.server_status, Server.Status.Pending)
     server._status_to_building()
     self.assertEqual(instance.server_status, Server.Status.Building)
     server._status_to_booting()
     self.assertEqual(instance.server_status, Server.Status.Booting)
     server._status_to_ready()
     self.assertEqual(instance.server_status, Server.Status.Ready)
     server._status_to_terminated()
     self.assertIsNone(instance.server_status)
     bad_instance = SingleVMOpenEdXInstanceFactory()
     bad_server = BuildingOpenStackServerFactory(instance=bad_instance)
     bad_server._status_to_build_failed()
     self.assertEqual(bad_instance.server_status, Server.Status.BuildFailed)
Beispiel #11
0
    def test_inventory_str(self, os_server_manager):
        """
        Ansible inventory - showing servers once they are in ready status
        """
        instance = SingleVMOpenEdXInstanceFactory()
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 0: 'pending'
        OpenStackServerFactory(instance=instance)
        self.assertEqual(instance.inventory_str, '[app]')

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

        # Server 2: 'failed'
        server2 = BuildingOpenStackServerFactory(instance=instance)
        server2._status_to_build_failed()
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 3: 'booting'
        server3 = BootingOpenStackServerFactory(instance=instance)
        os_server_manager.add_fixture(server3.openstack_id, 'openstack/api_server_2_active.json')
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 4: 'terminated'
        server4 = ReadyOpenStackServerFactory(instance=instance)
        server4._status_to_terminated()
        os_server_manager.add_fixture(server4.openstack_id, 'openstack/api_server_2_active.json')
        self.assertEqual(instance.inventory_str, '[app]')

        # Server 5: 'ready'
        server5 = ReadyOpenStackServerFactory(instance=instance)
        os_server_manager.add_fixture(server5.openstack_id, 'openstack/api_server_2_active.json')
        self.assertEqual(instance.inventory_str, '[app]\n192.168.100.200')

        # Server 6: 'ready'
        server6 = ReadyOpenStackServerFactory(instance=instance)
        os_server_manager.add_fixture(server6.openstack_id, 'openstack/api_server_3_active.json')
        self.assertEqual(instance.inventory_str, '[app]\n192.168.100.200\n192.168.99.66')