예제 #1
0
 def test_can_read_config_profile_data(self):
     loaded = load_wizard("""
     plan:
       start:
         values:
           foo:
             type: sharedconfig
             operation: GetValue
             params:
               profile: devprofile
               value: region
     """)
     config_api = mock.Mock(spec=core.SharedConfigAPI)
     config_api.get_value.return_value = 'us-west-2'
     sharedconfig = core.SharedConfigStep(
         config_api=config_api,
     )
     planner = core.Planner(
         step_handlers={
             'sharedconfig': sharedconfig,
         },
     )
     parameters = planner.plan(loaded['plan'])
     self.assertEqual(parameters['foo'], 'us-west-2')
     config_api.get_value.assert_called_with(profile='devprofile',
                                             value='region')
예제 #2
0
 def test_can_run_apicall_step_with_query(self):
     loaded = load_wizard("""
     plan:
       start:
         values:
           foo:
             type: apicall
             operation: iam.ListPolicies
             params:
               Scope: AWS
             query: Policies[].Name
     """)
     mock_session = mock.Mock(spec=Session)
     mock_client = mock.Mock()
     mock_session.create_client.return_value = mock_client
     mock_client.list_policies.return_value = {
         'Policies': [{'Name': 'one'}, {'Name': 'two'}],
     }
     api_step = core.APICallStep(
         api_invoker=core.APIInvoker(session=mock_session)
     )
     planner = core.Planner(
         step_handlers={
             'apicall': api_step,
         },
     )
     parameters = planner.plan(loaded['plan'])
     # Note this value is the result is applying the
     # Polices[].Name jmespath query to the response.
     self.assertEqual(parameters['foo'], ['one', 'two'])
예제 #3
0
 def test_can_run_apicall_step(self):
     loaded = load_wizard("""
     plan:
       start:
         values:
           foo:
             type: apicall
             operation: iam.ListPolicies
             params:
               Scope: AWS
     """)
     mock_session = mock.Mock(spec=Session)
     mock_client = mock.Mock()
     mock_session.create_client.return_value = mock_client
     mock_client.list_policies.return_value = {
         'Policies': ['foo'],
     }
     api_step = core.APICallStep(
         api_invoker=core.APIInvoker(session=mock_session)
     )
     planner = core.Planner(
         step_handlers={
             'apicall': api_step,
         },
     )
     parameters = planner.plan(loaded['plan'])
     self.assertEqual(parameters['foo'], {'Policies': ['foo']})
예제 #4
0
def create_default_wizard_runner(session):
    api_invoker = core.APIInvoker(session=session)
    shared_config = core.SharedConfigAPI(session=session,
                                         config_writer=ConfigFileWriter())
    planner = core.Planner(
        step_handlers={
            core.StaticStep.NAME:
            core.StaticStep(),
            core.PromptStep.NAME:
            core.PromptStep(ui.UIPrompter()),
            core.YesNoPrompt.NAME:
            core.YesNoPrompt(ui.UIPrompter()),
            core.FilePromptStep.NAME:
            core.FilePromptStep(ui.UIFilePrompter(ui.FileCompleter())),
            core.TemplateStep.NAME:
            core.TemplateStep(),
            core.APICallStep.NAME:
            core.APICallStep(api_invoker=api_invoker),
            core.SharedConfigStep.NAME:
            core.SharedConfigStep(config_api=shared_config),
        })
    executor = core.Executor(
        step_handlers={
            core.APICallExecutorStep.NAME:
            core.APICallExecutorStep(api_invoker),
            core.SharedConfigExecutorStep.NAME:
            core.SharedConfigExecutorStep(shared_config),
            core.DefineVariableStep.NAME:
            core.DefineVariableStep(),
            core.MergeDictStep.NAME:
            core.MergeDictStep(),
        })
    runner = core.Runner(planner, executor)
    return runner
예제 #5
0
 def setUp(self):
     self.responses = {}
     self.prompter = FakePrompter(self.responses)
     self.planner = core.Planner(
         step_handlers={
             'static': core.StaticStep(),
             'prompt': core.PromptStep(self.prompter),
             'yesno-prompt': core.YesNoPrompt(self.prompter),
             'template': core.TemplateStep(),
         }
     )
예제 #6
0
 def test_can_run_fileprompt_step(self):
     loaded = load_wizard("""
     plan:
       start:
         values:
           foo:
             type: fileprompt
             description: Select file
     """)
     prompter = mock.Mock(spec=ui.UIFilePrompter)
     prompter.prompt.return_value = 'myfile.txt'
     planner = core.Planner(
         step_handlers={
             'fileprompt': core.FilePromptStep(prompter=prompter),
         },
     )
     parameters = planner.plan(loaded['plan'])
     self.assertEqual(parameters['foo'],
                      os.path.abspath('myfile.txt'))
예제 #7
0
 def test_can_load_profiles(self):
     loaded = load_wizard("""
     plan:
       start:
         values:
           foo:
             type: sharedconfig
             operation: ListProfiles
     """)
     config_api = mock.Mock(spec=core.SharedConfigAPI)
     config_api.list_profiles.return_value = ['profile1', 'profile2']
     sharedconfig = core.SharedConfigStep(
         config_api=config_api,
     )
     planner = core.Planner(
         step_handlers={
             'sharedconfig': sharedconfig,
         },
     )
     parameters = planner.plan(loaded['plan'])
     self.assertEqual(parameters['foo'], ['profile1', 'profile2'])
예제 #8
0
    def test_can_delegate_to_arbitrary_type(self):

        class CustomStep(core.BaseStep):
            def run_step(self, step_definition, parameters):
                # Just return whatever the value of 'foo' is in the
                # step definition.
                return step_definition['foo']

        custom_step = CustomStep()
        custom_planner = core.Planner(
            step_handlers={
                'customstep': custom_step,
            },
        )
        loaded = load_wizard("""
        plan:
          start:
            values:
              name:
                type: customstep
                foo: myreturnvalue
        """)
        parameters = custom_planner.plan(loaded['plan'])
        self.assertEqual(parameters['name'], 'myreturnvalue')