Ejemplo n.º 1
0
    def test_create_new_plan_script(self):
        self.i3s.plan_scripts.get_by.return_value = []
        self.i3s.plan_scripts.create.return_value = {"name": "name"}

        self.mock_ansible_module.params = self.PLAN_SCRIPT_CREATE

        PlanScriptModule().run()

        self.i3s.plan_scripts.create.assert_called_once_with({
            'content':
            'echo "test script"',
            'planType':
            'deploy',
            'hpProvided':
            False,
            'description':
            'Description of this plan script',
            'name':
            'Demo Plan Script'
        })

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=PlanScriptModule.MSG_CREATED,
            ansible_facts=dict(plan_script={"name": "name"}))
Ejemplo n.º 2
0
    def test_should_do_nothing_when_deleting_a_non_existent_plan_script(self):
        self.i3s.plan_scripts.get_by.return_value = []

        self.mock_ansible_module.params = self.PLAN_SCRIPT_DELETE

        PlanScriptModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=PlanScriptModule.MSG_ALREADY_ABSENT)
Ejemplo n.º 3
0
    def test_delete_plan_script(self):
        self.i3s.plan_scripts.get_by.return_value = [self.PLAN_SCRIPT]

        self.mock_ansible_module.params = self.PLAN_SCRIPT_DELETE

        PlanScriptModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=PlanScriptModule.MSG_DELETED)
Ejemplo n.º 4
0
    def test_should_not_update_when_data_is_equals(self):
        self.resource.get_by.return_value = [PARAMS_UPDATE['data']]
        self.mock_ansible_module.params = PARAMS_UPDATE

        PlanScriptModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=PlanScriptModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(plan_script=PARAMS_UPDATE['data']))
    def test_should_fail_when_mandatory_attributes_are_missing(self):
        self.resource.get_by.return_value = []

        del self.PLAN_SCRIPT_DIFFERENCES['data']['content']

        self.mock_ansible_module.params = self.PLAN_SCRIPT_DIFFERENCES

        PlanScriptModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=PlanScriptModule.MSG_CONTENT_ATTRIBUTE_MANDATORY)
Ejemplo n.º 6
0
    def test_update_plan_script(self):
        self.i3s.plan_scripts.get_by.return_value = [self.PLAN_SCRIPT]
        self.i3s.plan_scripts.update.return_value = {"name": "name"}

        self.mock_ansible_module.params = self.PLAN_SCRIPT_UPDATE

        PlanScriptModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=PlanScriptModule.MSG_UPDATED,
            ansible_facts=dict(plan_script={"name": "name"}))
Ejemplo n.º 7
0
    def test_retrieve_plan_script_content_differences(self):
        self.resource.get_by.return_value = [self.PLAN_SCRIPT]
        self.resource.retrieve_differences.return_value = {"differences": []}

        self.mock_ansible_module.params = PARAMS_DIFFERENCE

        PlanScriptModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=PlanScriptModule.MSG_DIFFERENCES_RETRIEVED,
            ansible_facts=dict(plan_script_differences={"differences": []}))
Ejemplo n.º 8
0
    def test_create_new_plan_script(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = {"name": "Demo Plan Script"}

        self.mock_ansible_module.params = PARAMS_CREATE

        PlanScriptModule().run()

        self.resource.create.assert_called_once_with(
            {'name': 'Demo Plan Script'})

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=PlanScriptModule.MSG_CREATED,
            ansible_facts=dict(plan_script={"name": "Demo Plan Script"}))