Exemple #1
0
 def test_datetime(self):
     now = datetime.now()
     d = now + timedelta(seconds=0.1)
     timer = Timer(d, test(), "timer")
     timer.register(self.app)
     wait_for(self.app, "flag")
     self.app.reset()
Exemple #2
0
 def test_datetime(self):
     now = datetime.now()
     d = now + timedelta(seconds=0.1)
     timer = Timer(d, test(), "timer")
     timer.register(self.app)
     wait_for(self.app, "flag")
     self.app.reset()
Exemple #3
0
    def test_run_recorder(self):
        """
        - call session.run()
        - call session.succeed()

        Expected: vnc_recorder was started and stopped
        """
        with patch(
            'core.video.VNCVideoHelper._flvrec', Mock()
        ), patch(
            'core.video.VNCVideoHelper.start_recording', Mock()
        ) as start_rec_mock, patch(
            'core.video.VNCVideoHelper.stop', Mock()
        ) as stop_rec_mock, patch(
            'core.video.VNCVideoHelper.is_alive', Mock(return_value=True)
        ):
            from vmpool.artifact_collector import ArtifactCollector

            session = Mock(endpoint=Mock(prefix="ondemand", ip='127.0.0.1'), closed=False)
            artifact_collector = ArtifactCollector(database=DatabaseMock())
            artifact_collector.record_screencast(session)

            wait_for(lambda: artifact_collector.in_queue, timeout=5)

            session.closed = True

            wait_for(lambda: not artifact_collector.in_queue, timeout=5)
            self.assertTrue(start_rec_mock.called)
            self.assertTrue(stop_rec_mock.called)
    def test_connect_devices(self, device_spec):
        """
        - set config with 1 device
        - try to connect devices

        Expected: 1 device connected and 1 device in connected_devices list

        - stop stf-connect

        Expected: 0 devices connected and lists of devices was empty
        """
        with patch(
                'stf_utils.common.stfapi.SmartphoneTestingFarmAPI.get_all_devices',
                self.all_devices_mock,
        ), patch(
                'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.get_device',
                self.get_device_mock,
        ), patch(
                'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.add_device',
                Mock(),
        ), patch(
                'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.remote_connect',
                self.remote_connect_mock,
        ), patch(
                'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.delete_device',
                Mock(),
        ), patch(
                'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.remote_disconnect',
                Mock(),
        ), patch('stf_utils.common.adb.device_is_ready',
                 Mock(return_value=True)), patch(
                     'stf_utils.common.adb.connect',
                     Mock(return_value=True)), patch(
                         'stf_utils.common.adb.disconnect',
                         Mock(return_value=True)):
            stf = SmartphoneTestingFarmClient(
                host="http://host.domain",
                common_api_path="/api/v1",
                oauth_token="test token",
                device_spec=device_spec,
                devices_file_path="./devices",
                shutdown_emulator_on_disconnect=True)
            stf.connect_devices()

            wait_for(
                lambda: self.assertTrue(stf.shutdown_emulator_on_disconnect))
            wait_for(lambda: self.assertEqual(
                len(stf.device_groups[0].get("added_devices")),
                int(device_spec[0].get("amount"))))
            wait_for(lambda: self.assertEqual(
                len(stf.device_groups[0].get("connected_devices")),
                int(device_spec[0].get("amount"))))

            stf.close_all()

            wait_for(lambda: self.assertEqual(
                len(stf.device_groups[0].get("added_devices")), 0))
            wait_for(lambda: self.assertEqual(
                len(stf.device_groups[0].get("connected_devices")), 0))
Exemple #5
0
    def test_rebuild_preload_vm(self):
        """
        - call OpenstackClone.delete(try_to_rebuild=True)

        Expected: vm has been rebuilded and added in pool
        """
        self.clone.delete(try_to_rebuild=True)
        wait_for(lambda: self.clone.ready is True)
Exemple #6
0
    def test_persistent(self):
        timer = Timer(0.1, test(), "timer", persist=True)
        timer.register(self.app)

        for _ in range(2):
            wait_for(self.app, "flag")
            self.app.reset()

        timer.unregister()
Exemple #7
0
    def test_persistent(self):
        timer = Timer(0.1, test(), "timer", persist=True)
        timer.register(self.app)

        for _ in range(2):
            wait_for(self.app, "flag")
            self.app.reset()

        timer.unregister()
Exemple #8
0
    def test_exception_in_rebuild_vm_if_vm_exist(self):
        """
        - call OpenstackClone.create()
        - exception in OpenstackClone.delete(try_to_rebuild=True)

        Expected: vm has been deleted
        """
        self.clone.delete(try_to_rebuild=True)
        wait_for(lambda: self.clone.ready is False)
        self.assertTrue(self.clone.deleted)
Exemple #9
0
    def test_rebuild_after_delete_vm_if_vm_does_not_exist(self):
        """
        - get_vm return None
        - call OpenstackClone.delete(try_to_rebuild=True)

        Expected: vm has not been deleted
        """
        self.clone.delete(try_to_rebuild=True)
        wait_for(lambda: self.clone.ready is False)
        self.assertIsNone(self.clone.deleted)
Exemple #10
0
    def test_ping_success(self):
        """
        - call OpenstackClone.create()
        - ping success

        Expected: vm has been created
        """
        self.clone.create()
        wait_for(lambda: self.clone.ready)
        self.assertTrue(self.clone.ready)
Exemple #11
0
 def test_vm_in_error_status(self):
     """
     - call OpenstackClone.create()
     - first call server.status.lower() return "build",
       second call return "error"
       third call return "active"
     Expected: vm has been rebuilded
     """
     self.clone.create()
     wait_for(lambda: self.clone.ready is True)
     self.assertTrue(self.clone.ready)
Exemple #12
0
    def test_create_vm_with_get_ip(self):
        """
        - call OpenstackClone.create()
        - check_vm_exist is True
        - ping successful
        - ready is True
        - get_ip return mocked ip address and mac

        Expected: vm has been created
        """
        self.clone.create()
        wait_for(lambda: self.clone.ready is True)
        self.assertEqual(self.clone.ip, "127.0.0.1")
    def test_connect_devices(self, device_spec):
        """
        - set config with 1 device
        - try to connect devices

        Expected: 1 device connected and 1 device in connected_devices list

        - stop stf-connect

        Expected: 0 devices connected and lists of devices was empty
        """
        with patch(
            'stf_utils.common.stfapi.SmartphoneTestingFarmAPI.get_all_devices', self.all_devices_mock,
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.get_device', self.get_device_mock,
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.add_device', Mock(),
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.remote_connect', self.remote_connect_mock,
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.delete_device', Mock(),
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.remote_disconnect', Mock(),
        ), patch(
            'stf_utils.common.adb.device_is_ready', Mock(return_value=True)
        ), patch(
            'stf_utils.common.adb.connect', Mock(return_value=True)
        ), patch(
            'stf_utils.common.adb.disconnect', Mock(return_value=True)
        ):
            stf = SmartphoneTestingFarmClient(
                host="http://host.domain",
                common_api_path="/api/v1",
                oauth_token="test token",
                device_spec=device_spec,
                devices_file_path="./devices",
                shutdown_emulator_on_disconnect=True
            )
            stf.connect_devices()

            wait_for(lambda: self.assertTrue(stf.shutdown_emulator_on_disconnect))
            wait_for(lambda: self.assertEqual(len(stf.device_groups[0].get("added_devices")), int(device_spec[0].get("amount"))))
            wait_for(lambda: self.assertEqual(len(stf.device_groups[0].get("connected_devices")), int(device_spec[0].get("amount"))))

            stf.close_all()

            wait_for(lambda: self.assertEqual(len(stf.device_groups[0].get("added_devices")), 0))
            wait_for(lambda: self.assertEqual(len(stf.device_groups[0].get("connected_devices")), 0))
    def test_500_code_run_script_during_add_tasks(self):
        """
        - add tasks

        Expected: selenium log was saved and endpoint was deleted
        """
        from vmpool.artifact_collector import ArtifactCollector
        with patch(
            'core.db.Database', DatabaseMock()
        ):
            from core.db.models import Session, Endpoint, Provider
            session = Session("origin_1")
            session.id = self.session_id

            provider = Provider(name='noname', url='nourl')
            endpoint = Endpoint(Mock(), '', provider)
            endpoint.ip = '127.0.0.1'
            endpoint.name = 'test_endpoint'
            endpoint.ports = {'selenium': '4455', 'agent': '9000', 'vnc': '5900'}

            session.endpoint = endpoint
            art_collector = ArtifactCollector(database=Mock())
            in_queue = art_collector.save_artifact(session, 'selenium_server.log', '/var/log/selenium_server.log')

        self.assertTrue(in_queue)
        self.assertTrue(wait_for(
            lambda: len(art_collector.get_queue()) == 0))

        art_collector.stop()
    def test_unavailable_run_script_during_add_tasks(self):
        """
        - add tasks

        Expected: selenium log was saved and endpoint was deleted
        """
        from vmpool.artifact_collector import ArtifactCollector
        with patch(
            'core.db.Database', DatabaseMock()
        ):
            from core.db.models import Session, Endpoint, Provider
            session = Session("origin_1")
            session.id = self.session_id
            log_path = os.sep.join([self.artifact_dir, 'selenium_server.log'])

            provider = Provider(name='noname', url='nourl')
            endpoint = Endpoint(Mock(), '', provider)
            endpoint.ip = '127.0.0.1'
            endpoint.name = 'test_endpoint'
            endpoint.ports = {'selenium': '4455', 'agent': '9000', 'vnc': '5900'}

            session.endpoint = endpoint
            self.app.sessions.get_session = Mock(return_value=session)

            art_collector = ArtifactCollector(database=Mock())
            in_queue = art_collector.save_artifact(session, 'selenium_server.log', '/var/log/selenium_server.log')

        self.assertTrue(in_queue)
        self.assertTrue(wait_for(
            lambda: len(art_collector.get_queue()) == 0))
        with open(log_path, 'r') as f:
            text = f.read()
            self.assertIn('Connection refused', text)

        art_collector.stop()
    def test_connect_new_device_after_device_lost(self, device_spec):
        """
        - set config with 1 device
        - try to connect devices

        Expected: 1 device connected and 1 device in connected_devices list

        - start devices watcher
        - got 'False' in device_is_ready method (connected device is not available)

        Expected: 0 devices connected and lists of devices was empty
        (device was removed from stf-connect and device by adb was disconnected)

        - try to connect available devices

        Expected: 1 device connected and 1 device in connected_devices list
        """
        def raise_exception():
            raise Exception('something ugly happened in adb connect')

        with patch(
            'stf_connect.client.SmartphoneTestingFarmClient.get_all_devices', self.all_devices_mock,
        ), patch(
            'stf_connect.client.SmartphoneTestingFarmClient.get_device', self.get_device_mock,
        ), patch(
            'stf_connect.client.SmartphoneTestingFarmClient.add_device', Mock(),
        ), patch(
            'stf_connect.client.SmartphoneTestingFarmClient.remote_connect', self.remote_connect_mock,
        ), patch(
            'common.adb.device_is_ready', Mock(side_effect=[False, True, True])
        ), patch(
            'common.adb.connect', Mock(side_effect=[True, raise_exception, True])
        ), patch(
            'common.adb.disconnect', Mock(return_value=True)
        ):
            stf = SmartphoneTestingFarmClient(
                host="http://host.domain",
                common_api_path="/api/v1",
                oauth_token="test token",
                device_spec=device_spec,
                devices_file_path="./devices",
                shutdown_emulator_on_disconnect=True
            )
            stf.connect_devices()

            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("added_devices")) == int(device_spec[0].get("amount"))))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("connected_devices")) == int(device_spec[0].get("amount"))))

            self.watcher = STFConnectedDevicesWatcher(stf)
            self.watcher.start()

            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("added_devices")) == 0))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("connected_devices")) == 0))

            stf.connect_devices()

            self.assertTrue(wait_for(lambda: stf.shutdown_emulator_on_disconnect))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("added_devices")) == int(device_spec[0].get("amount"))))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("connected_devices")) == int(device_spec[0].get("amount"))))
    def test_connect_new_device_after_device_lost(self, device_spec):
        """
        - set config with 1 device
        - try to connect devices

        Expected: 1 device connected and 1 device in connected_devices list

        - start devices watcher
        - got 'False' in device_is_ready method (connected device is not available)

        Expected: 0 devices connected and lists of devices was empty
        (device was removed from stf-connect and device by adb was disconnected)

        - try to connect available devices

        Expected: 1 device connected and 1 device in connected_devices list
        """
        def raise_exception():
            raise Exception('something ugly happened in adb connect')

        with patch(
            'stf_utils.common.stfapi.SmartphoneTestingFarmAPI.get_all_devices', self.all_devices_mock,
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.get_device', self.get_device_mock,
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.add_device', Mock(),
        ), patch(
            'stf_utils.stf_connect.client.SmartphoneTestingFarmClient.remote_connect', self.remote_connect_mock,
        ), patch(
            'stf_utils.common.adb.device_is_ready', Mock(side_effect=[False, True, True])
        ), patch(
            'stf_utils.common.adb.connect', Mock(side_effect=[True, raise_exception, True])
        ), patch(
            'stf_utils.common.adb.disconnect', Mock(return_value=True)
        ):
            stf = SmartphoneTestingFarmClient(
                host="http://host.domain",
                common_api_path="/api/v1",
                oauth_token="test token",
                device_spec=device_spec,
                devices_file_path="./devices",
                shutdown_emulator_on_disconnect=True
            )
            stf.connect_devices()

            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("added_devices")) == int(device_spec[0].get("amount"))))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("connected_devices")) == int(device_spec[0].get("amount"))))

            self.watcher = STFConnectedDevicesWatcher(stf)
            self.watcher.start()

            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("added_devices")) == 0))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("connected_devices")) == 0))

            stf.connect_devices()

            self.assertTrue(wait_for(lambda: stf.shutdown_emulator_on_disconnect))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("added_devices")) == int(device_spec[0].get("amount"))))
            self.assertTrue(wait_for(lambda: len(stf.device_groups[0].get("connected_devices")) == int(device_spec[0].get("amount"))))
 def testSequence(self):
     frames = mock.Mock()
     sequence = Sequence(frames, [0], [1], 400, 10)
     frames.assert_not_called()
     self.assertFalse(sequence.isRunning())
     sequence.setFrame(2)
     self.assertEqual(sequence.current_frame, 2)
     sequence.setFrame(-1)
     self.assertEqual(sequence.current_frame, 9)
     sequence.start()
     self.assertTrue(sequence.isRunning())
     sequence.stop()
     self.assertEqual(sequence.current_frame, 9)
     frames.assert_called()
     frames.reset_mock()
     sequence.start()
     self.assertTrue(sequence.isRunning())
     wait_for(lambda: not sequence.isRunning(), 500)
     self.assertFalse(sequence.isRunning())
    def test_stop_artifact_collector(self):
        """
        - stop artifact collector

        Expected: all tasks were deleted
        """
        from vmpool.artifact_collector import ArtifactCollector, Task
        from multiprocessing.pool import AsyncResult

        art_collector = ArtifactCollector(database=Mock())
        task = AsyncResult(cache={1: ""}, callback=None)
        task._job = 1
        task._ready = True
        art_collector.in_queue = {
            1: [Task('my_task', task)]
        }
        art_collector.stop()

        self.assertTrue(wait_for(
            lambda: len(art_collector.get_queue()) == 0))
Exemple #20
0
 def testName(self):
     wait_for(self._conf_comp, "value", "Yes")
     self.assertEqual(self._conf_comp.value, "Yes")
Exemple #21
0
 def testName(self):
     wait_for(self._conf_comp, "value", "Yes")
     self.assertEqual(self._conf_comp.value, "Yes")
Exemple #22
0
 def test_basic(self):
     timer = Timer(0.1, test(), "timer")
     timer.register(self.app)
     wait_for(self.app, "flag")
     self.app.reset()
Exemple #23
0
 def test_basic(self):
     timer = Timer(0.1, test(), "timer")
     timer.register(self.app)
     wait_for(self.app, "flag")
     self.app.reset()