def test_service_action_with_duration(self, action, service_name, t): command = '%s %s service for %d seconds' % (action, service_name, t) human.execute(self.destructor, command) self.destructor.get_service.assert_called_once_with(name=service_name) getattr(self.service, action).assert_called_once_with(sec=t)
def human_api(distractor, command): """Execute high-level text command with specified destructor :param destructor: library instance as returned by :connect: function :param command: text command """ human.execute(distractor, command)
def test_service_action(self, action, service_name): command = '%s %s service' % (action, service_name) human.execute(self.destructor, command) self.destructor.get_service.assert_called_once_with(name=service_name) getattr(self.service, action).assert_called_once_with()
def human_api(cloud_management, command): """Executes a command written as English sentence :param cloud_management: library instance as returned by :connect: function :param command: text command """ human.execute(cloud_management, command)
def test_network_on_nodes_by_fqdn(self, user_action, action): destructor = mock.MagicMock() nodes = mock.MagicMock(node_collection.NodeCollection) destructor.get_nodes = mock.MagicMock(return_value=nodes) command = '%s storage network on node-2.local node' % user_action human.execute(destructor, command) destructor.get_nodes.assert_called_once_with(fqdns=['node-2.local']) getattr(nodes, action).assert_called_once_with(network_name='storage')
def test_node_action_by_fqdn(self, action): destructor = mock.MagicMock() nodes = mock.MagicMock(node_collection.NodeCollection) destructor.get_nodes = mock.MagicMock(return_value=nodes) command = '%s node-2.local node' % action.capitalize() human.execute(destructor, command) destructor.get_nodes.assert_called_once_with(fqdns=['node-2.local']) getattr(nodes, action).assert_called_once()
def test_node_action_on_all_nodes(self, action, service_name): nodes = mock.MagicMock(node_collection.NodeCollection) self.service.get_nodes = mock.MagicMock(return_value=nodes) command = '%s node with %s service' % (action, service_name) human.execute(self.destructor, command) self.destructor.get_service.assert_called_once_with(name=service_name) getattr(nodes, action).assert_called_once_with()
def test_service_action_on_fqdn_node(self, action, service_name, node): nodes = mock.MagicMock(node_collection.NodeCollection) self.destructor.get_nodes.return_value = nodes command = '%s %s service on %s node' % (action, service_name, node) human.execute(self.destructor, command) self.destructor.get_service.assert_called_once_with(name=service_name) self.destructor.get_nodes.assert_called_once_with(fqdns=[node]) getattr(self.service, action).assert_called_once_with(nodes=nodes)
def test_stress_by_service_on_fqdn_node(self, user_target, cmd_target, duration, service_name): action = 'stress' nodes = mock.MagicMock(node_collection.NodeCollection) self.service.get_nodes.return_value = nodes command = 'stress %s for %d seconds on all nodes with %s service' % ( user_target, duration, service_name) human.execute(self.destructor, command) getattr(nodes, action).assert_called_once_with(target=cmd_target, duration=duration)
def test_network_on_nodes_by_service(self, action, network_name, service_name): nodes = mock.MagicMock(node_collection.NodeCollection) self.service.get_nodes = mock.MagicMock(return_value=nodes) command = '%s %s network on node with %s service' % ( action, network_name, service_name) human.execute(self.destructor, command) self.destructor.get_service.assert_called_once_with(name=service_name) self.service.get_nodes.assert_called_once() getattr(nodes, action).assert_called_once_with(network_name=network_name)
def test_stress_target(self, target): action = 'stress' duration = 20 destructor = mock.MagicMock() nodes = mock.MagicMock(node_collection.NodeCollection) destructor.get_nodes = mock.MagicMock(return_value=nodes) command = 'stress %s for %d seconds on nodes' % (target, duration) human.execute(destructor, command) destructor.get_nodes.assert_called_once_with() getattr(nodes, action).assert_called_once_with(target=target, duration=duration)
def test_service_action_on_random_node(self, action, service_name, node): nodes = mock.MagicMock(node_collection.NodeCollection) self.service.get_nodes = mock.MagicMock(return_value=nodes) one_node = mock.MagicMock(node_collection.NodeCollection) nodes.pick = mock.MagicMock(return_value=one_node) command = '%s %s service on %s node' % (action, service_name, node) human.execute(self.destructor, command) self.destructor.get_service.assert_called_once_with(name=service_name) getattr(self.service, action).assert_called_once_with(nodes=one_node) nodes.pick.assert_called_once()
def test_unplug_with_ref(self, action, service_name, direction, other_service_name): other_port = ('tcp', mock.Mock()) other_service = mock.Mock() other_service.port = other_port self.destructor.get_service.side_effect = [self.service, other_service] command = '%s %s service %s to %s service' % ( action, service_name, direction, other_service_name) human.execute(self.destructor, command) self.destructor.get_service.assert_has_calls( [mock.call(name=service_name), mock.call(name=other_service_name)]) getattr(self.service, action).assert_called_once_with(direction=direction, other_port=other_port)