def test_module_assign_physical_host_no_current_fileset( self, mock_get, mock_post, mock_patch): set_module_args({ 'hostname': 'hostname', 'fileset_name': 'fileset', 'sla_name': 'gold', 'operating_system': 'Linux', 'node_ip': '1.1.1.1', 'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP' }) mock_get.side_effect = [ mock_get_v1_host(), mock_get_v1_fileset_template(), mock_get_v1_sla_domain(), mock_get_no_fileset() ] mock_post.return_value = mock_post_v1_fileset() mock_patch.return_value = mock_patch_v1_fileset() with self.assertRaises(AnsibleExitJson) as result: rubrik_assign_physical_host_fileset.main() self.assertEqual(result.exception.args[0]['changed'], True) self.assertEqual(result.exception.args[0]['response'][0], mock_post_v1_fileset()) self.assertEqual(result.exception.args[0]['response'][1], mock_patch_v1_fileset())
def test_module_fail_with_invalid_fileset_name_multiple_matches_specific( self, mock_get): set_module_args({ 'hostname': 'hostname', 'fileset_name': 'fileset', 'sla_name': 'gold', 'operating_system': 'Linux', 'include': [""], 'exclude': ["", True, True], 'node_ip': '1.1.1.1', 'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP' }) mock_get.side_effect = [ mock_get_v1_host(), mock_get_multiple_matching_fileset_templates() ] with self.assertRaises(AnsibleFailJson) as result: rubrik_assign_physical_host_fileset.main() self.assertEqual(result.exception.args[0]['failed'], True) self.assertEqual( result.exception.args[0]['msg'], """The Rubrik cluster contains multiple Linux Filesets named 'fileset' that match all of the populate function arguments. Please use a unique Fileset.""" ) # nopep8
def test_module_fail_with_invalid_operating_system(self): set_module_args({ 'hostname': 'test-host', 'fileset_name': 'fileset', 'sla_name': 'gold', 'operating_system': 'osx' }) with self.assertRaises(AnsibleFailJson): rubrik_assign_physical_host_fileset.main()
def test_module_fail_with_invalid_backup_hidden_folders(self): set_module_args({ 'hostname': 'test-host', 'fileset_name': 'fileset', 'sla_name': 'gold', 'operating_system': 'Linux', 'backup_hidden_folders': 'Yes' }) with self.assertRaises(AnsibleFailJson): rubrik_assign_physical_host_fileset.main()
def test_module_fail_with_invalid_hostname(self, mock_get): set_module_args({ 'hostname': 'invalid-host', 'fileset_name': 'fileset', 'sla_name': 'gold', 'operating_system': 'Linux', 'node_ip': '1.1.1.1', 'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP' }) mock_get.return_value = mock_get_no_host() with self.assertRaises(AnsibleFailJson) as result: rubrik_assign_physical_host_fileset.main() self.assertEqual(result.exception.args[0]['failed'], True) self.assertEqual( result.exception.args[0]['msg'], "The Rubrik cluster is not connected to a Linux physical host named 'invalid-host'." )
def test_module_assign_physical_host_fileset_idempotence(self, mock_get): set_module_args({ 'hostname': 'hostname', 'fileset_name': 'fileset', 'sla_name': 'gold', 'operating_system': 'Linux', 'node_ip': '1.1.1.1', 'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP' }) mock_get.side_effect = [ mock_get_v1_host(), mock_get_v1_fileset_template(), mock_get_v1_sla_domain(), mock_get_existing_fileset() ] with self.assertRaises(AnsibleExitJson) as result: rubrik_assign_physical_host_fileset.main() self.assertEqual(result.exception.args[0]['changed'], False)
def test_module_fail_with_invalid_fileset_name(self, mock_get): set_module_args({ 'hostname': 'hostname', 'fileset_name': 'invalid-fileset', 'sla_name': 'gold', 'operating_system': 'Linux', 'node_ip': '1.1.1.1', 'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP' }) mock_get.side_effect = [ mock_get_v1_host(), mock_get_no_fileset_template() ] with self.assertRaises(AnsibleFailJson) as result: rubrik_assign_physical_host_fileset.main() self.assertEqual(result.exception.args[0]['failed'], True) self.assertEqual( result.exception.args[0]['msg'], "The Rubrik cluster does not have a Linux Fileset named 'invalid-fileset'." )
def test_module_fail_when_required_args_missing(self): with self.assertRaises(AnsibleFailJson): set_module_args({}) rubrik_assign_physical_host_fileset.main()