예제 #1
0
파일: executor.py 프로젝트: tflink/checkb
    def _spawn_vm(self, uuid, playbook_vars):
        '''Spawn a virtual machine using testcloud.

        :param str uuid: unicode string uuid for the task being executed
        :param dict playbook_vars: a vars dict created by
            :meth:`_create_playbook_vars`
        :returns: str ip address of spawned vm
        '''
        log.info('Spawning disposable client')

        env = image_utils.devise_environment(self.arg_data, playbook_vars)
        self.task_vm = vm.TestCloudMachine(uuid)

        retries = config.get_config().spawn_vm_retries

        while retries > 0:
            retries -= 1
            try:
                self.task_vm.prepare(**env)
                self.task_vm.wait_for_port(22)

                log.debug('Disposable client (%s %s) ready',
                          self.task_vm.instancename, self.task_vm.ipaddr)

                return self.task_vm.ipaddr
            except vm.TestcloudInstanceError as e:
                if retries <= 0:
                    raise exc.CheckbMinionError(
                        'Disposable client failed '
                        'to boot: %s', e)
                else:
                    log.warning(
                        'Disposable client failed to boot, retrying: '
                        '%s', e)
                    self.task_vm.teardown()
예제 #2
0
    def should_raise_existing_expecting_novm(self, monkeypatch):
        stub_instance = Mock(return_value=None)

        monkeypatch.setattr(instance, 'find_instance', stub_instance)

        test_vm = vm.TestCloudMachine(self.ref_uuid)

        with pytest.raises(exc.CheckbRemoteError):
            test_vm._check_existing_instance(True)
예제 #3
0
    def should_be_quiet_on_success(self, monkeypatch):
        test_vm = vm.TestCloudMachine(self.ref_uuid)
        mock_instance = Mock()
        mock_check_instance = Mock(return_value=mock_instance)
        monkeypatch.setattr(test_vm, '_check_existing_instance',
                            mock_check_instance)

        test_vm.teardown()
        assert len(mock_instance.mock_calls) == 1
예제 #4
0
    def should_raise_on_failure(self, monkeypatch):
        test_vm = vm.TestCloudMachine(self.ref_uuid)
        mock_instance = Mock()
        mock_instance.remove.side_effect = tce.TestcloudInstanceError()
        mock_check_instance = Mock(return_value=mock_instance)
        monkeypatch.setattr(test_vm, '_check_existing_instance',
                            mock_check_instance)

        with pytest.raises(exc.CheckbRemoteError):
            test_vm.teardown()
예제 #5
0
    def should_return_none_expecting_novm(self, monkeypatch):
        stub_instance = Mock(return_value=None)

        monkeypatch.setattr(instance, 'find_instance', stub_instance)

        test_vm = vm.TestCloudMachine(self.ref_uuid)

        test_instance = test_vm._check_existing_instance(False)

        assert test_instance is None
예제 #6
0
    def should_return_instance_found_expecting_vm(self, monkeypatch):
        stub_found_instance = Mock()
        stub_instance = Mock(return_value=stub_found_instance)

        monkeypatch.setattr(instance, 'find_instance', stub_instance)

        test_vm = vm.TestCloudMachine(self.ref_uuid)

        test_instance = test_vm._check_existing_instance(True)

        assert test_instance == stub_found_instance
예제 #7
0
    def should_behave_on_success(self, monkeypatch):
        stub_image = MagicMock()

        monkeypatch.setattr(image, 'Image', stub_image)
        monkeypatch.setattr(vm.ImageFinder, 'get_latest_metadata', Mock())

        test_vm = vm.TestCloudMachine(self.ref_uuid)

        test_vm._prepare_image(distro=None,
                               release=None,
                               flavor=None,
                               arch=None)
예제 #8
0
    def should_make_proper_calls(self, monkeypatch):
        stub_image = Mock()
        stub_instance = MagicMock()
        stub_instanceclass = Mock(return_value=stub_instance)

        monkeypatch.setattr(instance, 'Instance', stub_instanceclass)

        test_vm = vm.TestCloudMachine(self.ref_uuid)

        test_vm._prepare_instance(stub_image)

        assert stub_instance.method_calls == [('prepare', ), ('spawn_vm', ),
                                              ('start', )]
예제 #9
0
    def should_raise_on_failure(self, monkeypatch):
        stub_image = Mock(side_effect=tce.TestcloudImageError())

        monkeypatch.setattr(image, 'Image', stub_image)
        monkeypatch.setattr(vm.ImageFinder, 'get_latest_metadata', Mock())

        test_vm = vm.TestCloudMachine(self.ref_uuid)

        with pytest.raises(exc.CheckbImageError):
            test_vm._prepare_image(distro=None,
                                   release=None,
                                   flavor=None,
                                   arch=None)