Exemple #1
0
    def test_module_fail_with_incorrect_hostname_list_when_action_is_delete(
            self):
        set_module_args({
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'action': 'delete',
            'hostname': ['hostname1', 'hostname2'],
        })

        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_physical_host.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            "A list of hostnames is not supported when action is delete.")
Exemple #2
0
    def test_module_idempotence_delete(self, mock_get):
        def mock_get_v1_host():
            return {
                "hasMore":
                True,
                "data": [{
                    "id": "string",
                    "name": "string",
                    "hostname": "string",
                    "primaryClusterId": "string",
                    "operatingSystem": "string",
                    "operatingSystemType": "string",
                    "status": "string",
                    "nasBaseConfig": {
                        "vendorType": "string",
                        "apiUsername": "******",
                        "apiCertificate": "string",
                        "apiHostname": "string",
                        "apiEndpoint": "string",
                        "zoneName": "string"
                    },
                    "mssqlCbtEnabled": "Enabled",
                    "mssqlCbtEffectiveStatus": "On",
                    "organizationId": "string",
                    "organizationName": "string"
                }],
                "total":
                1
            }

        set_module_args({
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'action': 'delete',
            'hostname': "hostname"
        })

        mock_get.return_value = mock_get_v1_host()

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_physical_host.main()

        self.assertEqual(result.exception.args[0]['changed'], False)
        self.assertEqual(
            result.exception.args[0]['response'],
            "No change required. The host 'hostname' is not connected to the Rubrik cluster."
        )
Exemple #3
0
    def test_module_configure_rubrik_physical_host_add(self, mock_get,
                                                       mock_post):
        def mock_get_v1_host():
            return {
                "hasMore":
                True,
                "data": [{
                    "id": "string",
                    "name": "string",
                    "hostname": "string",
                    "primaryClusterId": "string",
                    "operatingSystem": "string",
                    "operatingSystemType": "string",
                    "status": "string",
                    "nasBaseConfig": {
                        "vendorType": "string",
                        "apiUsername": "******",
                        "apiCertificate": "string",
                        "apiHostname": "string",
                        "apiEndpoint": "string",
                        "zoneName": "string"
                    },
                    "mssqlCbtEnabled": "Enabled",
                    "mssqlCbtEffectiveStatus": "On",
                    "organizationId": "string",
                    "organizationName": "string"
                }],
                "total":
                1
            }

        def mock_post_v1_host():
            return {
                "id": "string",
                "name": "string",
                "hostname": "string",
                "primaryClusterId": "string",
                "operatingSystem": "string",
                "operatingSystemType": "string",
                "status": "string",
                "nasBaseConfig": {
                    "vendorType": "string",
                    "apiUsername": "******",
                    "apiCertificate": "string",
                    "apiHostname": "string",
                    "apiEndpoint": "string",
                    "zoneName": "string"
                },
                "mssqlCbtEnabled": "Enabled",
                "mssqlCbtEffectiveStatus": "On",
                "organizationId": "string",
                "organizationName": "string",
                "agentId": "string",
                "compressionEnabled": True,
                "isRelic": True,
                "mssqlCbtDriverInstalled": True,
                "hostVfdEnabled": "Enabled",
                "hostVfdDriverState": "NotInstalled",
                "oracleSysDbaUser": "******"
            }

        set_module_args({
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'action': 'add',
            'hostname': 'hostname'
        })

        mock_get.return_value = mock_get_v1_host()

        mock_post.return_value = mock_post_v1_host()

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_physical_host.main()

        self.assertEqual(result.exception.args[0]['changed'], True)
        self.assertEqual(result.exception.args[0]['response'],
                         mock_post_v1_host())
Exemple #4
0
 def test_module_fail_when_required_args_missing(self):
     with self.assertRaises(AnsibleFailJson):
         set_module_args({})
         rubrik_physical_host.main()
Exemple #5
0
    def test_module_configure_rubrik_physical_host_delete(
            self, mock_get, mock_delete):
        def mock_get_v1_host():
            return {
                "hasMore":
                True,
                "data": [{
                    "id": "string",
                    "name": "string",
                    "hostname": "hostname",
                    "primaryClusterId": "string",
                    "operatingSystem": "string",
                    "operatingSystemType": "string",
                    "status": "string",
                    "nasBaseConfig": {
                        "vendorType": "string",
                        "apiUsername": "******",
                        "apiCertificate": "string",
                        "apiHostname": "string",
                        "apiEndpoint": "string",
                        "zoneName": "string"
                    },
                    "mssqlCbtEnabled": "Enabled",
                    "mssqlCbtEffectiveStatus": "On",
                    "organizationId": "string",
                    "organizationName": "string"
                }, {
                    "id": "string",
                    "name": "string",
                    "hostname": "string",
                    "primaryClusterId": "string",
                    "operatingSystem": "string",
                    "operatingSystemType": "string",
                    "status": "string",
                    "nasBaseConfig": {
                        "vendorType": "string",
                        "apiUsername": "******",
                        "apiCertificate": "string",
                        "apiHostname": "string",
                        "apiEndpoint": "string",
                        "zoneName": "string"
                    },
                    "mssqlCbtEnabled": "Enabled",
                    "mssqlCbtEffectiveStatus": "On",
                    "organizationId": "string",
                    "organizationName": "string"
                }],
                "total":
                2
            }

        def mock_delete_v1_host_id():

            set_module_args({
                'node_ip': '1.1.1.1',
                'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
                'action': 'delete',
                'hostname': 'hostname'
            })

            return {"status_code": "204"}

        set_module_args({
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'action': 'delete',
            'hostname': 'hostname'
        })

        mock_get.return_value = mock_get_v1_host()

        mock_delete.return_value = mock_delete_v1_host_id()

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_physical_host.main()

        self.assertEqual(result.exception.args[0]['changed'], True)
        self.assertEqual(result.exception.args[0]['response'],
                         mock_delete_v1_host_id())