Пример #1
0
 def test_add_node_idempotent(self, mock_create_sf_connection):
     ''' adding a node that is already in the cluster '''
     args = dict(self.ARGS)
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(where='nodes')
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert not exc.value.args[0]['changed']
Пример #2
0
 def test_add_node(self, mock_create_sf_connection):
     ''' adding a node '''
     args = dict(self.ARGS)  # deep copy as other tests can modify args
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(where='pending')
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
Пример #3
0
 def test_remove_node_idempotent(self, mock_create_sf_connection):
     ''' removing a node that is not in the cluster '''
     args = dict(self.ARGS)
     args['state'] = 'absent'
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert not exc.value.args[0]['changed']
Пример #4
0
 def test_add_node_fail_not_pending(self, mock_create_sf_connection):
     ''' adding a node - fails as these nodes are unknown '''
     args = dict(self.ARGS)  # deep copy as other tests can modify args
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     msg = 'nodes not in pending or active lists'
     assert msg in exc.value.args[0]['msg']
Пример #5
0
 def test_remove_node_with_active_drive(self, mock_create_sf_connection):
     ''' removing a node that is in the cluster but still associated with a drive '''
     args = dict(self.ARGS)
     args['state'] = 'absent'
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(node_id=NODE_ID1, where='nodes')
     my_obj = my_module()
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     msg = 'Error deleting node %s: node has active drives' % NODE_NAME1
     assert msg in exc.value.args[0]['msg']
Пример #6
0
 def test_set_cluster_name_and_add_idempotent(self, mock_create_sf_connection):
     ''' set cluster name and add the node '''
     args = dict(self.ARGS)
     args['cluster_name'] = 'cluster_name'
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(where='nodes', cluster_name=args['cluster_name'])
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert not exc.value.args[0]['changed']
     message = ''
     assert message == exc.value.args[0]['msg']
Пример #7
0
 def test_set_cluster_name_only(self, mock_create_sf_connection):
     ''' set cluster name without adding the node '''
     args = dict(self.ARGS)
     args['preset_only'] = True
     args['cluster_name'] = 'cluster_name'
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection()
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
     message = 'List of updated nodes with cluster_name:'
     assert message in exc.value.args[0]['msg']
Пример #8
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'])