def test_add_duplicate(self): request_1 = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies(), )) request_2 = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies(), )) self.mock_get_current_backend() response_1 = jsonish_dict_to_rpc( self.call_api('add_machine', request_1).json, rpc_messages.CatalogManipulationResponse, ) response_2 = jsonish_dict_to_rpc( self.call_api('add_machine', request_2).json, rpc_messages.CatalogManipulationResponse, ) self.failIf(response_1.error) self.assertEqual( response_2.error, rpc_messages.CatalogManipulationRequestError.HOSTNAME_REUSE, )
def test_delete_invalid(self): request_1 = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host-1', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), )) request_2 = rpc_to_json( rpc_messages.CatalogMachineDeletionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host-2', os_family=rpc_messages.OSFamily.LINUX, ), )) request_3 = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host-1', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), )) self.mock_get_current_backend() response_1 = jsonish_dict_to_rpc( self.call_api('add_machine', request_1).json, rpc_messages.CatalogManipulationResponse, ) response_2 = jsonish_dict_to_rpc( self.call_api('delete_machine', request_2).json, rpc_messages.CatalogManipulationResponse, ) response_3 = jsonish_dict_to_rpc( self.call_api('add_machine', request_3).json, rpc_messages.CatalogManipulationResponse, ) self.failIf(response_1.error) self.assertEqual( response_2.error, rpc_messages.CatalogManipulationRequestError.ENTRY_NOT_FOUND, ) self.assertEqual( response_3.error, rpc_messages.CatalogManipulationRequestError.HOSTNAME_REUSE, )
def test_add_batch(self): request = rpc_to_json( rpc_messages.CatalogMachineBatchAdditionRequest(requests=[ rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host-1', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), ), rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host-2', os_family=rpc_messages.OSFamily.WINDOWS, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), ), rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host-1', os_family=rpc_messages.OSFamily.OSX, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), ), ], )) self.mock_get_current_backend() response = jsonish_dict_to_rpc( self.call_api('add_machines', request).json, rpc_messages.CatalogBatchManipulationResponse, ) self.assertEqual(len(response.responses), 3) self.failIf(response.responses[0].error) self.failIf(response.responses[1].error) self.assertEqual( response.responses[2].error, rpc_messages.CatalogManipulationRequestError.HOSTNAME_REUSE, )
def test_delete(self): request_1 = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), )) request_2 = rpc_to_json( rpc_messages.CatalogMachineDeletionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), )) request_3 = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.WINDOWS, ), policies=rpc_messages.Policies( backend_project='fake-project', backend_topic='fake-topic', ), )) self.mock_get_current_backend() response_1 = jsonish_dict_to_rpc( self.call_api('add_machine', request_1).json, rpc_messages.CatalogManipulationResponse, ) response_2 = jsonish_dict_to_rpc( self.call_api('delete_machine', request_2).json, rpc_messages.CatalogManipulationResponse, ) response_3 = jsonish_dict_to_rpc( self.call_api('add_machine', request_3).json, rpc_messages.CatalogManipulationResponse, ) self.failIf(response_1.error) self.failIf(response_2.error) self.failIf(response_3.error)
def test_add(self): request = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies(), )) self.mock_get_current_backend() response = jsonish_dict_to_rpc( self.call_api('add_machine', request).json, rpc_messages.CatalogManipulationResponse, ) self.failIf(response.error)
def test_add_no_hostname(self): request = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies(), )) self.mock_get_current_backend() response = jsonish_dict_to_rpc( self.call_api('add_machine', request).json, rpc_messages.CatalogManipulationResponse, ) self.assertEqual( response.error, rpc_messages.CatalogManipulationRequestError.UNSPECIFIED_HOSTNAME, )
def test_add_project_without_topic(self): request = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies(pubsub_project='my-project', ), )) self.mock_get_current_backend() response = jsonish_dict_to_rpc( self.call_api('add_machine', request).json, rpc_messages.CatalogManipulationResponse, ) self.assertEqual( response.error, rpc_messages.CatalogManipulationRequestError.UNSPECIFIED_TOPIC, )
def test_add_invalid_topic(self): request = rpc_to_json( rpc_messages.CatalogMachineAdditionRequest( dimensions=rpc_messages.Dimensions( hostname='fake-host', os_family=rpc_messages.OSFamily.LINUX, ), policies=rpc_messages.Policies( pubsub_topic='../../a-different-project/topics/my-topic', ), )) self.mock_get_current_backend() response = jsonish_dict_to_rpc( self.call_api('add_machine', request).json, rpc_messages.CatalogManipulationResponse, ) self.assertEqual( response.error, rpc_messages.CatalogManipulationRequestError.INVALID_TOPIC, )