def test_create_idempotent(self, mock_create_sf_connection):
     ''' cluster already exists with same nodes '''
     args = dict(self.ARGS)
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(nodes=[NODE_ID1, NODE_ID2])
     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']
     assert 'send_request' not in my_obj.sfe_node.called
     assert 'create_cluster' not in my_obj.sfe_node.called
 def test_create_idempotent_extra_nodes(self, mock_create_sf_connection):
     ''' cluster already exists with more nodes '''
     args = dict(self.ARGS)
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(nodes=[NODE_ID1, NODE_ID2, NODE_ID3])
     my_obj = my_module()
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     msg = 'Error: found existing cluster with more nodes in ensemble.'
     assert msg in exc.value.args[0]['msg']
     assert 'send_request' not in my_obj.sfe_node.called
     assert 'create_cluster' not in my_obj.sfe_node.called
 def test_create_extra_parms(self, mock_create_sf_connection):
     ''' force a direct call to send_request '''
     args = dict(self.ARGS)  # deep copy as other tests can modify args
     args['order_number'] = '12345'
     args['serial_number'] = '54321'
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(force_error=True, where='get_config_exception')
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
     assert 'send_request' in my_obj.sfe_node.called
     assert 'create_cluster' not in my_obj.sfe_node.called
 def test_create(self, mock_create_sf_connection):
     ''' create cluster basic '''
     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(force_error=True, where='get_config_exception')
     my_obj = my_module()
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print(exc.value.args[0])
     assert exc.value.args[0]['changed']
     msg = 'created'
     assert msg in exc.value.args[0]['msg']
     assert 'create_cluster' in my_obj.sfe_node.called
     assert 'send_request' not in my_obj.sfe_node.called
 def test_create_idempotent_missing_nodes(self, mock_create_sf_connection):
     ''' cluster already exists with fewer nodes.
         Since not every node is lister in the ensemble, we can't tell if it's an error or not '''
     args = dict(self.ARGS)
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(nodes=[NODE_ID1])
     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']
     msg = 'cluster already exists'
     assert msg in exc.value.args[0]['msg']
     assert 'send_request' not in my_obj.sfe_node.called
     assert 'create_cluster' not in my_obj.sfe_node.called
 def test_create_idempotent_extra_nodes_ok(self, mock_create_sf_connection):
     ''' cluster already exists with more nodes but we're OK with a superset '''
     args = dict(self.ARGS)
     args['fail_if_cluster_already_exists_with_larger_ensemble'] = False
     set_module_args(args)
     # my_obj.sfe will be assigned a MockSFConnection object:
     mock_create_sf_connection.return_value = MockSFConnection(nodes=[NODE_ID1, NODE_ID2, NODE_ID3])
     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']
     msg = 'cluster already exists'
     assert msg in exc.value.args[0]['msg']
     assert 'send_request' not in my_obj.sfe_node.called
     assert 'create_cluster' not in my_obj.sfe_node.called
 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'])