def testValidateDeviceActions(self):
    action = ndb_models.DeviceAction(
        device_type='LOCAL_VIRTUAL',
        tradefed_options=[
            ndb_models.NameMultiValuePair(
                name='gce-driver-param', values=['--boot-timeout']),
            ndb_models.NameMultiValuePair(
                name='gce-driver-param', values=['600'])
        ])

    with self.assertRaises(ValueError):
      test_kicker.ValidateDeviceActions(
          [action, ndb_models.DeviceAction(device_type='PHYSICAL')])

    with self.assertRaises(ValueError):
      test_kicker.ValidateDeviceActions([action, action])

    test_kicker.ValidateDeviceActions([
        action,
        ndb_models.DeviceAction(
            device_type='LOCAL_VIRTUAL',
            tradefed_options=[
                ndb_models.NameMultiValuePair(
                    name='gce-driver-path', values=['/bin/acloud_prebuilt'])
            ])
    ])
 def _CreateMockDeviceAction(self,
                             action_id='action.id',
                             name='device action name'):
     """Creates a mock ndb_models.DeviceAction object."""
     device_action = ndb_models.DeviceAction(name=name)
     device_action.key = mtt_messages.ConvertToKey(ndb_models.DeviceAction,
                                                   action_id)
     device_action.put()
     return device_action
 def _CreateMockDeviceAction(self,
                             action_id='action.id',
                             namespace='',
                             name='Device Action 1'):
     if namespace:
         action_id = config_encoder._AddNamespaceToId(namespace, action_id)
     action = ndb_models.DeviceAction(name=name)
     action.key = ndb.Key(ndb_models.DeviceAction, action_id)
     action.put()
     return action
Exemplo n.º 4
0
def _DeviceActionMessageConverter(msg):
  return ndb_models.DeviceAction(
      key=ConvertToKeyOrNone(ndb_models.DeviceAction, msg.id),
      name=msg.name,
      description=msg.description,
      test_resource_defs=ConvertList(
          msg.test_resource_defs, ndb_models.TestResourceDef),
      tradefed_target_preparers=ConvertList(
          msg.tradefed_target_preparers, ndb_models.TradefedConfigObject),
      device_type=msg.device_type,
      tradefed_options=ConvertNameValuePairs(
          msg.tradefed_options, ndb_models.NameMultiValuePair))
 def testApplyOptionsFromDeviceActions(self):
     """Tests that device actions can be found and executed."""
     device_action = ndb_models.DeviceAction(
         name='unit test',
         tradefed_options=[
             ndb_models.NameMultiValuePair(name='device-type',
                                           values=['LOCAL_VIRTUAL_DEVICE'])
         ])
     test_run = ndb_models.TestRun(before_device_actions=[device_action])
     test_run.put()
     task = mock.MagicMock(extra_options={})
     test_run_hook._ApplyOptionsFromDeviceActions(test_run.key.id(), task)
     self.assertEqual(task.extra_options,
                      {'device-type': ['LOCAL_VIRTUAL_DEVICE']})
  def testKickTestPlan(self, create_test_run):
    """Tests that a test plan can be kicked off."""
    test = ndb_models.Test(id='test_id')
    test_device_action = ndb_models.DeviceAction(id='test_device_action')
    test_run_action = ndb_models.TestRunAction(id='test_run_action')
    # Create a test plan with multiple resources and actions
    test_plan = ndb_models.TestPlan(
        name='test_plan',
        labels=['label'],
        cron_exp='0 0 * * *',
        test_run_configs=[
            ndb_models.TestRunConfig(
                test_key=test.key,
                cluster='cluster',
                run_target='run_target',
                before_device_action_keys=[test_device_action.key],
                test_run_action_refs=[
                    ndb_models.TestRunActionRef(action_key=test_run_action.key),
                ],
                test_resource_objs=[
                    ndb_models.TestResourceObj(name='res_1', url='url_1')]),
        ])
    test_plan.put()
    # Test run will be created successfully
    test_run = ndb_models.TestRun(id='test_run_id')
    create_test_run.return_value = test_run

    executed = test_plan_kicker.KickTestPlan(test_plan.key.id())
    self.assertTrue(executed)

    # Test run is created with the right test and test plan components
    create_test_run.assert_called_with(
        labels=['label'],
        test_plan_key=test_plan.key,
        test_run_config=ndb_models.TestRunConfig(
            test_key=test.key,
            cluster='cluster',
            run_target='run_target',
            before_device_action_keys=[test_device_action.key],
            test_run_action_refs=[
                ndb_models.TestRunActionRef(action_key=test_run_action.key),
            ],
            test_resource_objs=[
                ndb_models.TestResourceObj(name='res_1', url='url_1')
            ]),
        )
    # Test run key is stored in the test plan status
    status = ndb_models.TestPlanStatus.query(ancestor=test_plan.key).get()
    self.assertEqual(status.last_run_keys, [test_run.key])
Exemplo n.º 7
0
    def Get(self, request):
        """Fetches a device action.

    Parameters:
      device_action_id: Device action ID
    """
        if request.device_action_id == '0':
            device_action = ndb_models.DeviceAction(name='')
        else:
            device_action = mtt_messages.ConvertToKey(
                ndb_models.DeviceAction, request.device_action_id).get()
        if not device_action:
            raise endpoints.NotFoundException('No device action with ID %s' %
                                              request.device_action_id)
        return mtt_messages.Convert(device_action, mtt_messages.DeviceAction)
Exemplo n.º 8
0
    def setUp(self):
        super(TestPlanApiTest, self).setUp(test_plan_api.TestPlanApi)
        self.mock_test = ndb_models.Test(name='mock_test', command='command')
        self.mock_test.put()
        self.mock_test_id = str(self.mock_test.key.id())
        self.mock_build_channel = ndb_models.BuildChannelConfig(
            id=str(uuid.uuid4()),
            name='mock_build_channel',
            provider_name='mock_build_provider')
        self.mock_build_channel.put()
        self.mock_build_channel_id = self.mock_build_channel.key.id()
        self.mock_device_action = ndb_models.DeviceAction(
            name='mock_device_action')
        self.mock_device_action.put()
        self.mock_device_action_id = str(self.mock_device_action.key.id())

        build_item = base.BuildItem(name='zz',
                                    path='/foo/bar/zz',
                                    is_file=True)
        self.mock_test_resource_url = build.BuildUrl(
            self.mock_build_channel_id, build_item)
 def _CreateDeviceAction(self, name='action'):
     obj = ndb_models.DeviceAction(name=name)
     obj.put()
     return obj