コード例 #1
0
 def testUnnecessaryCleanup(self):
     data = {
         'title':
         '',
         'actions': [
             {
                 'generate_resource_id': {
                     'reference': 'my-device',
                     'prefix': 'iot-device',
                     'requires_cleanup': False
                 }
             },
             {
                 'execute_command': {
                     'command': '',
                     'cleanup_for': 'my-device',
                     'events': []
                 }
             },
         ]
     }
     validator = schema.Validator(data)
     with self.assertRaisesRegex(
             schema.ValidationError,
             r'cleanup_for reference \[my-device\] was marked as not requiring '
             r'cleanup'):
         validator.Validate()
コード例 #2
0
 def testMissingCleanup(self):
     data = {
         'title':
         '',
         'actions': [{
             'generate_resource_id': {
                 'reference': 'my-device',
                 'prefix': 'iot-device'
             }
         }, {
             'generate_resource_id': {
                 'reference': 'my-device2',
                 'prefix': 'iot-device'
             }
         }, {
             'execute_command': {
                 'command': '',
                 'events': []
             }
         }]
     }
     validator = schema.Validator(data)
     with self.assertRaisesRegex(
             schema.ValidationError,
             r'No cleanup_for rules found for generate_resource_id action: '
             r'\[my-device\]\n'
             r'No cleanup_for rules found for generate_resource_id action: '
             r'\[my-device2\]\n'):
         validator.Validate()
コード例 #3
0
 def testDuplicateCleanup(self):
     data = {
         'title':
         '',
         'actions': [
             {
                 'generate_resource_id': {
                     'reference': 'my-device',
                     'prefix': 'iot-device'
                 }
             },
             {
                 'execute_command': {
                     'command': '',
                     'cleanup_for': 'my-device',
                     'events': []
                 }
             },
             {
                 'execute_command': {
                     'command': '',
                     'cleanup_for': 'my-device',
                     'events': []
                 }
             },
         ]
     }
     validator = schema.Validator(data)
     with self.assertRaisesRegex(
             schema.ValidationError,
             r'Duplicate cleanup_for reference found: \[my-device\]'):
         validator.Validate()
コード例 #4
0
 def testValidateTemplate(self):
     val = pkg_resources.GetResourceFromFile(SCENARIO_TEMPLATE_PATH)
     template = yaml.load(val, version=yaml.VERSION_1_2)
     validator = scenario_schema.Validator(template)
     try:
         validator.Validate()
     except scenario_schema.ValidationError as e:
         self.fail(e)
コード例 #5
0
 def testValidateCreateExample(self):
     example = yaml.load(
         pkg_resources.GetResourceFromFile(CREATE_EXAMPLE_PATH),
         version=yaml.VERSION_1_2)
     validator = scenario_schema.Validator(example)
     try:
         validator.Validate()
     except scenario_schema.ValidationError as e:
         self.fail(e)
コード例 #6
0
 def testMissingMissingGenerated(self):
     data = {
         'title':
         '',
         'actions': [{
             'execute_command': {
                 'command': '',
                 'cleanup_for': 'asdf',
                 'events': []
             }
         }]
     }
     validator = schema.Validator(data)
     with self.assertRaisesRegex(
             schema.ValidationError,
             r'cleanup_for reference \[asdf\] was not found in a '
             r'generate_resource_id action'):
         validator.Validate()
コード例 #7
0
  def RunScenario(self, spec_path, track, execution_mode, update_modes,
                  debug=False):
    full_spec_path = sdk_test_base.SdkBase.Resource(spec_path)
    spec_data = yaml.load_path(
        full_spec_path, round_trip=True, version=yaml.VERSION_1_2)
    validator = schema.Validator(spec_data)
    try:
      validator.Validate()
    except schema.ValidationError as e:
      self.fail(e)

    spec = schema.Scenario.FromData(spec_data)

    self.track = track
    stream_mocker = CreateStreamMocker(self)

    scenario_context = schema.ScenarioContext(
        spec_path, full_spec_path, spec_data, track, execution_mode,
        update_modes, stream_mocker, self.Run, debug)
    self.StartPatch(
        'googlecloudsdk.core.console.console_io.CanPrompt', return_value=True)
    if execution_mode == session.ExecutionMode.LOCAL:
      self.StartObjectPatch(retry, '_SleepMs')

    actions = spec.LoadActions()
    for a in actions:
      try:
        a.Execute(scenario_context)
      except assertions.Error:
        if execution_mode == session.ExecutionMode.REMOTE:
          for c in actions:
            # Iterates over the remaining actions because it is a generator.
            c.ExecuteCleanup(scenario_context)
        # Continue raising the original error.
        raise

    if update_modes:
      spec.UpdateSummary(scenario_context)
コード例 #8
0
 def testBadSchema(self):
     data = {'title': '', 'actions': [], 'foo': 'bar'}
     validator = schema.Validator(data)
     with self.assertRaises(schema.ValidationError):
         validator.Validate()