Example #1
0
 def test_remove_node_name_and_id(self):
     ''' creating add_node'''
     data = self.set_default_args()
     # del data['cluster_name']
     data['cluster_ip_address'] = '10.10.10.10'
     data['node_name'] = 'node3'
     data['state'] = 'absent'
     set_module_args(data)
     with pytest.raises(AnsibleFailJson) as exc:
         my_module()
     print('Info: test_remove_node_name_and_id: %s' % repr(exc.value))
     msg = 'when state is "absent", parameters are mutually exclusive: cluster_ip_address|node_name'
     assert msg in exc.value.args[0]['msg']
Example #2
0
 def test_ensure_license_get_called(self):
     ''' fetching details of license '''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = self.server
     license_get = my_obj.get_licensing_status()
     print('Info: test_license_get: %s' % repr(license_get))
     assert not bool(license_get)
Example #3
0
 def test_if_all_methods_catch_exception(self):
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_cluster()
     assert 'Error creating cluster' in exc.value.args[0]['msg']
     data = self.set_default_args()
     data['cluster_ip_address'] = '10.10.10.10'
     set_module_args(data)
     my_obj = my_module()
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.add_node()
     assert 'Error adding node with ip' in exc.value.args[0]['msg']
 def test_cluster_create_called(self, cluster_create):
     ''' creating cluster'''
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_success')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     cluster_create.assert_called_with()
 def test_ensure_apply_for_cluster_called(self):
     ''' creating cluster and checking idempotency '''
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
 def test_cluster_join_called(self, cluster_join):
     ''' creating cluster_join'''
     data = self.set_default_args()
     del data['cluster_name']
     data['cluster_ip_address'] = '10.10.10.10'
     set_module_args(data)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_add')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     cluster_join.assert_called_with()
Example #7
0
 def test_cluster_create_old_api(self, get_cl_id, sleep_mock):
     ''' creating cluster'''
     get_cl_id.return_value = None
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_extra_input')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
Example #8
0
 def test_cluster_create_old_api_other_extra(self, get_cl_id):
     ''' creating cluster'''
     get_cl_id.return_value = None
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_extra_input_other')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     msg = 'TEST3:Extra input: other-unexpected-element'
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     assert msg in exc.value.args[0]['msg']
Example #9
0
 def test_add_node_called(self, add_node, get_cl_id, get_cl_ips):
     ''' creating add_node'''
     get_cl_ips.return_value = list()
     get_cl_id.return_value = None
     data = self.set_default_args()
     del data['cluster_name']
     data['cluster_ip_address'] = '10.10.10.10'
     set_module_args(data)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_add')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     add_node.assert_called_with()
     assert exc.value.args[0]['changed']
Example #10
0
 def test_remove_node_name(self, wait, remove_node, get_cl_id, get_cl_nodes):
     ''' creating add_node'''
     get_cl_nodes.return_value = ['node1', 'node2']
     get_cl_id.return_value = None
     wait.return_value = None
     data = self.set_default_args()
     # del data['cluster_name']
     data['node_name'] = 'node2'
     data['state'] = 'absent'
     set_module_args(data)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_add')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     remove_node.assert_called_with()
     assert exc.value.args[0]['changed']
Example #11
0
 def test_remove_node_ip_idempotent(self, remove_node, get_cl_id, get_cl_ips):
     ''' creating add_node'''
     get_cl_ips.return_value = list()
     get_cl_id.return_value = None
     data = self.set_default_args()
     # del data['cluster_name']
     data['cluster_ip_address'] = '10.10.10.10'
     data['state'] = 'absent'
     set_module_args(data)
     my_obj = my_module()
     my_obj.autosupport_log = Mock(return_value=None)
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_add')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_cluster_apply: %s' % repr(exc.value))
     try:
         remove_node.assert_not_called()
     except AttributeError:
         # not supported with python <= 3.4
         pass
     assert not exc.value.args[0]['changed']
Example #12
0
 def test_if_all_methods_catch_exception(self):
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     if not self.use_vsim:
         my_obj.server = MockONTAPConnection('cluster_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.get_licensing_status()
     assert 'Error checking license status' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_cluster()
     assert 'Error creating cluster' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.cluster_join()
     assert 'Error adding node to cluster' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.license_v2_add()
     assert 'Error adding license' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.license_v2_delete()
         assert 'Error deleting license' in exc.value.args[0]['msg']
Example #13
0
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         my_module()
     print('Info: %s' % exc.value.args[0]['msg'])