def test_empty_requirements(self): blueprint = 'blueprint_without_plugins' blueprint_path = '{0}/local/{1}.yaml'.format( test_cli_command.BLUEPRINTS_DIR, blueprint) cli_runner.run_cli( 'aria init --install-plugins -p {0} -b {1}' .format(blueprint_path, blueprint))
def _assert_ex(self, cli_cmd, err_str_segment, possible_solutions=None): def _assert(): self.assertIn(err_str_segment, str(ex)) if possible_solutions: if hasattr(ex, 'possible_solutions'): self.assertEqual(ex.possible_solutions, possible_solutions) else: self.fail('Exception should have ' 'declared possible solutions') try: cli_runner.run_cli(cli_cmd) self.fail('Expected error {0} was not raised for command {1}' .format(err_str_segment, cli_cmd)) except (exceptions.AriaError, SystemExit, exceptions.AriaValidationError, ValueError, IOError, ImportError, Exception) as ex: _assert()
def test_local_execute_with_params_allow_custom_true(self): b_id = self._local_init() self._local_execute(b_id, parameters={ 'custom_param': 'custom_param_value'}, allow_custom=True) cli_runner.run_cli( 'aria outputs -b {0}'.format(b_id))
def test_install_plugins(self): blueprint_path = '{0}/local/blueprint_with_plugins.yaml'\ .format(BLUEPRINTS_DIR) try: cli_runner.run_cli( 'aria install-plugins -p {0}'.format(blueprint_path)) except CommandExecutionException as e: # Expected pip install to start self.assertIn('pip install -r /tmp/requirements_', e.message)
def assert_method_called(self, cli_command, module, function_name, kwargs): with patch.object(module, function_name) as mock: try: cli_runner.run_cli(cli_command) except BaseException as e: self.logger.info(e.message) mock.assert_called_with(**kwargs)
def test_install_plugins(self): blueprint_path = '{0}/local/blueprint_with_plugins.yaml'\ .format(BLUEPRINTS_DIR) try: cli_runner.run_cli('aria install-plugins -p {0}' .format(blueprint_path)) except CommandExecutionException as e: # Expected pip install to start self.assertIn('pip install -r /tmp/requirements_', e.message)
def test_all_commands(self): """ Run all commands. """ all_commands = get_all_commands() for command in all_commands: possible_commands = get_combinations(command) for possible_command in possible_commands: cli_runner.run_cli("aria {0}".format(possible_command))
def test_install_plugins(self): blueprint_path = ('{0}/local/blueprint_with_plugins.yaml'. format(test_cli_command.BLUEPRINTS_DIR)) try: cli_runner.run_cli('aria install-plugins -p {0}' .format(blueprint_path)) except futures.aria_aside_exceptions.CommandExecutionException as e: # Expected pip install to start self.assertIn('pip install -r ', e.message)
def test_all_commands_verbose(self): """ Run all commands with 'verbosity' flags. """ all_commands = get_all_commands() for command in all_commands: possible_commands = get_combinations(command) for possible_command in possible_commands: cli_runner.run_cli("aria {0} -v".format(possible_command)) cli_runner.run_cli("aria {0} --verbose".format(possible_command))
def test_install_agent(self): blueprint_path = '{0}/local/install-agent-blueprint.yaml' \ .format(BLUEPRINTS_DIR) try: cli_runner.run_cli('aria init -p {0}'.format(blueprint_path)) self.fail('ValueError was expected') except ValueError as e: self.assertIn("'install_agent': true is not supported " "(it is True by default) " "when executing local workflows. " "The 'install_agent' property must be set to false " "for each node of type {0}.".format(HOST_TYPE), e.message)
def test_install_agent(self): blueprint_path = '{0}/local/install-agent-blueprint.yaml' \ .format(BLUEPRINTS_DIR) try: cli_runner.run_cli('aria init -p {0}'.format(blueprint_path)) self.fail('ValueError was expected') except ValueError as e: self.assertIn( "'install_agent': true is not supported " "(it is True by default) " "when executing local workflows. " "The 'install_agent' property must be set to false " "for each node of type {0}.".format(HOST_TYPE), e.message)
def _local_init(self, inputs=None, blueprint='blueprint', install_plugins=False): blueprint_path = '{0}/local/{1}.yaml'.format(BLUEPRINTS_DIR, blueprint) flags = '--install-plugins' if install_plugins else '' command = 'aria init {0} -p {1}'.format(flags, blueprint_path) if inputs: inputs_path = os.path.join(TEST_WORK_DIR, 'temp_inputs.json') with open(inputs_path, 'w') as f: f.write(json.dumps(inputs)) command = '{0} -i {1}'.format(command, inputs_path) cli_runner.run_cli(command)
def test_create_requirements(self): from aria_cli.tests.resources.blueprints import local expected_requirements = { 'http://localhost/plugin.zip', os.path.join(os.path.dirname(local.__file__), 'plugins', 'local_plugin'), 'http://localhost/host_plugin.zip' } requirements_file_path = os.path.join(TEST_WORK_DIR, 'requirements.txt') cli_runner.run_cli( 'aria create-requirements -p ' '{0}/local/blueprint_with_plugins.yaml -o {1}'.format( BLUEPRINTS_DIR, requirements_file_path)) with open(requirements_file_path, 'r') as f: actual_requirements = set(f.read().split()) self.assertEqual(actual_requirements, expected_requirements)
def _local_init(self, inputs=None, blueprint='blueprint', install_plugins=False, custom_blueprint_id=None): b_id = (blueprint if not custom_blueprint_id else custom_blueprint_id) blueprint_path = '{0}/local/{1}.yaml'.format( test_cli_command.BLUEPRINTS_DIR, blueprint) flags = '--install-plugins' if install_plugins else '' command = 'aria init {0} -b {2} -p {1}'.format( flags, blueprint_path, b_id) if inputs: inputs_path = os.path.join(test_cli_command.TEST_WORK_DIR, 'temp_inputs.json') with open(inputs_path, 'w') as f: f.write(json.dumps(inputs)) command = '{0} -i {1}'.format(command, inputs_path) cli_runner.run_cli(command) return b_id
def _assert_ex(self, cli_cmd, err_str_segment, possible_solutions=None): def _assert(): self.assertIn(err_str_segment, str(ex)) if possible_solutions: if hasattr(ex, 'possible_solutions'): self.assertEqual(ex.possible_solutions, possible_solutions) else: self.fail('Exception should have ' 'declared possible solutions') try: cli_runner.run_cli(cli_cmd) self.fail('Expected error {0} was not raised for command {1}' .format(err_str_segment, cli_cmd)) except SystemExit, ex: _assert()
def test_create_requirements(self): from aria_cli.tests.resources.blueprints import local expected_requirements = { 'http://localhost/plugin.zip', os.path.join( os.path.dirname(local.__file__), 'plugins', 'local_plugin'), 'http://localhost/host_plugin.zip'} requirements_file_path = os.path.join(TEST_WORK_DIR, 'requirements.txt') cli_runner.run_cli('aria create-requirements -p ' '{0}/local/blueprint_with_plugins.yaml -o {1}' .format(BLUEPRINTS_DIR, requirements_file_path)) with open(requirements_file_path, 'r') as f: actual_requirements = set(f.read().split()) self.assertEqual(actual_requirements, expected_requirements)
def test_create_requirements_no_output(self): from aria_cli.tests.resources.blueprints import local expected_requirements = { 'http://localhost/plugin.zip', os.path.join(os.path.dirname(local.__file__), 'plugins', 'local_plugin'), 'http://localhost/host_plugin.zip' } output = cli_runner.run_cli( 'aria create-requirements -p ' '{0}/local/blueprint_with_plugins.yaml'.format(BLUEPRINTS_DIR)) for requirement in expected_requirements: self.assertIn(requirement, output)
def test_create_requirements_no_output(self): from aria_cli.tests.resources.blueprints import local expected_requirements = { 'http://localhost/plugin.zip', os.path.join( os.path.dirname(local.__file__), 'plugins', 'local_plugin'), 'http://localhost/host_plugin.zip'} output = cli_runner.run_cli( 'aria create-requirements -p ' '{0}/local/blueprint_with_plugins.yaml' .format(BLUEPRINTS_DIR)) for requirement in expected_requirements: self.assertIn(requirement, output)
def _local_execute(self, parameters=None, allow_custom=None, workflow_name='run_test_op_on_nodes'): if parameters: parameters_path = os.path.join(TEST_WORK_DIR, 'temp_parameters.json') with open(parameters_path, 'w') as f: f.write(json.dumps(parameters)) command = 'aria execute -w {0} -p {1}'\ .format(workflow_name, parameters_path) if allow_custom is True: cli_runner.run_cli( '{0} --allow-custom-parameters'.format(command)) elif allow_custom is False: self._assert_ex(command, 'does not have the following') else: cli_runner.run_cli(command) else: cli_runner.run_cli('aria execute -w {0}'.format(workflow_name))
def _local_execute(self, parameters=None, allow_custom=None, workflow_name='run_test_op_on_nodes'): if parameters: parameters_path = os.path.join(TEST_WORK_DIR, 'temp_parameters.json') with open(parameters_path, 'w') as f: f.write(json.dumps(parameters)) command = 'aria execute -w {0} -p {1}'\ .format(workflow_name, parameters_path) if allow_custom is True: cli_runner.run_cli('{0} --allow-custom-parameters' .format(command)) elif allow_custom is False: self._assert_ex(command, 'does not have the following') else: cli_runner.run_cli(command) else: cli_runner.run_cli('aria execute -w {0}' .format(workflow_name))
def test_local_init(self): self._local_init() output = cli_runner.run_cli('aria outputs') self.assertIn('"param": null', output) self.assertIn('"custom_param": null', output) self.assertIn('"input1": "default_input1"', output)
def test_local_instances_with_existing_node_id(self): b_id = self._local_init() self._local_execute(b_id) cli_runner.run_cli( 'aria instances -b {0} --node-id node'.format(b_id))
def test_local_instances(self): self._local_init() self._local_execute() output = cli_runner.run_cli('aria instances') self.assertIn('"node_id": "node"', output)
def test_local_instances_with_existing_node_id(self): self._local_init() self._local_execute() output = cli_runner.run_cli('aria instances --node-id node') self.assertIn('"node_id": "node"', output)
def test_empty_requirements(self): blueprint = 'blueprint_without_plugins' blueprint_path = '{0}/local/{1}.yaml'.format(BLUEPRINTS_DIR, blueprint) cli_runner.run_cli( 'aria init --install-plugins -p {0}'.format(blueprint_path))
def test_local_execute_with_params_allow_custom_true(self): self._local_init() self._local_execute(parameters={'custom_param': 'custom_param_value'}, allow_custom=True) output = cli_runner.run_cli('aria outputs') self.assertIn('"custom_param": "custom_param_value"', output)
def test_local_instances(self): b_id = self._local_init() self._local_execute(b_id) cli_runner.run_cli( 'aria instances -b {0}'.format(b_id))
def test_install_plugins_missing_windows_agent_installer(self): blueprint_path = '{0}/local/windows_installers_blueprint.yaml'\ .format(BLUEPRINTS_DIR) cli_runner.run_cli('aria init -p {0}'.format(blueprint_path))
def test_local_execute(self): self._local_init() self._local_execute() output = cli_runner.run_cli('aria outputs') self.assertIn('"param": "default_param"', output)
def _test_all_combinations(self, command_path): possible_commands = get_combinations(command_path) for command in possible_commands: cli_runner.run_cli("aria {0}".format(command))
def test_local_execute_with_params(self): b_id = self._local_init() self._local_execute(b_id, parameters={'param': 'new_param'}) cli_runner.run_cli( 'aria outputs -b {0}'.format(b_id))
def test_create_requirements_no_output(self): cli_runner.run_cli( 'aria create-requirements -p ' '{0}/local/blueprint_with_plugins.yaml' .format(test_cli_command.BLUEPRINTS_DIR))
def test_local_execute_with_params(self): self._local_init() self._local_execute(parameters={'param': 'new_param'}) output = cli_runner.run_cli('aria outputs') self.assertIn('"param": "new_param"', output)
def test_local_init_with_inputs(self): self._local_init(inputs={'input1': 'new_input1'}) output = cli_runner.run_cli('aria outputs') self.assertIn('"input1": "new_input1"', output)
def test_local_init(self): b_id = self._local_init() cli_runner.run_cli( 'aria outputs -b {0}'.format(b_id))
def test_local_init_with_inputs(self): blueprint_id = self._local_init( inputs={'input1': 'new_input1'}) cli_runner.run_cli( 'aria outputs -b {0}'.format(blueprint_id))
def test_blueprint_validate(self): cli_runner.run_cli('aria validate ' '-p {0}/helloworld/blueprint.yaml' .format(BLUEPRINTS_DIR))
def test_local_execute(self): blueprint_id = self._local_init() self._local_execute(blueprint_id) cli_runner.run_cli( 'aria outputs -b {0}'.format(blueprint_id))