def test_module_physical_host_current_sla(self, mock_get, mock_post,
                                              mock_cluster_version):
        set_module_args({
            'object_name': 'test-host',
            'object_type': 'physical_host',
            'host_os': 'Linux',
            'fileset': 'fileset',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        mock_cluster_version.return_value = "5.0"

        mock_get.side_effect = [
            mock_get_v1_host(),
            mock_get_v1_fileset_template(),
            mock_get_v1_fileset()
        ]

        mock_post.return_value = mock_post_v1_fileset_id_snapshot()

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

        self.assertEqual(result.exception.args[0]['changed'], True)
        self.assertEqual(result.exception.args[0]['response'],
                         mock_post_v1_fileset_id_snapshot())
        self.assertEqual(result.exception.args[0]['job_status_url'],
                         'href_string')
    def test_module_fail_with_physical_host_invalid_fileset(
            self, mock_get, mock_cluster_version):
        set_module_args({
            'object_name': 'test-host',
            'object_type': 'physical_host',
            'host_os': 'Linux',
            'fileset': 'fileset',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        mock_cluster_version.return_value = "5.0"

        mock_get.side_effect = [
            mock_get_v1_host(),
            mock_get_v1_fileset_template(),
            mock_get_no_fileset()
        ]

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

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            "The Physical Host 'test-host' is not assigned to the 'fileset' Fileset."
        )
    def test_module_fail_with_physical_host_host_os_not_populated(self):
        set_module_args({
            'object_name': 'test-vm',
            'object_type': 'physical_host',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })
        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_on_demand_snapshot.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            "The on_demand_snapshot() `host_os` argument must be populated when taking a Physical host snapshot."
        )
    def test_module_fail_with_incorrect_host_os(self):
        set_module_args({
            'object_name': 'test-vm',
            'object_type': 'vmware',
            'host_os': 'foo',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })
        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_on_demand_snapshot.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            "value of host_os must be one of: None, Linux, Windows, got: foo")
    def test_module_ahv_specific_sla(self, mock_get, mock_post):
        set_module_args({
            'object_name': 'test-vm',
            'object_type': 'ahv',
            'sla_name': 'Gold',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        mock_get.side_effect = [
            mock_get_internal_nutanix_vm(),
            mock_get_v1_sla_domain()
        ]

        mock_post.return_value = mock_post_internal_nutanix_vm_id_snapshot()

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

        self.assertEqual(result.exception.args[0]['changed'], True)
        self.assertEqual(result.exception.args[0]['job_status_url'],
                         'href_string')
 def test_module_fail_when_required_args_missing(self):
     with self.assertRaises(AnsibleFailJson):
         set_module_args({})
         rubrik_on_demand_snapshot.main()