Revision ec7b6d63 qa/qa_group.py

b/qa/qa_group.py
24 24
"""
25 25

  
26 26
from ganeti import constants
27
from ganeti import netutils
27 28
from ganeti import query
28 29
from ganeti import utils
29 30

  
31
import qa_iptables
30 32
import qa_config
31 33
import qa_utils
32 34

  
......
41 43
  return groups.get("group-with-nodes", constants.INITIAL_NODE_GROUP_NAME)
42 44

  
43 45

  
46
def ConfigureGroups():
47
  """Configures groups and nodes for tests such as custom SSH ports.
48

  
49
  """
50

  
51
  defgroup = GetDefaultGroup()
52
  nodes = qa_config.get("nodes")
53
  options = qa_config.get("options", {})
54

  
55
  # Clear any old configuration
56
  qa_iptables.CleanRules(nodes)
57

  
58
  # Custom SSH ports:
59
  ssh_port = options.get("ssh-port")
60
  default_ssh_port = netutils.GetDaemonPort(constants.SSH)
61
  if (ssh_port is not None) and (ssh_port != default_ssh_port):
62
    ModifyGroupSshPort(qa_iptables.GLOBAL_RULES, defgroup, nodes, ssh_port)
63

  
64

  
65
def ModifyGroupSshPort(ipt_rules, group, nodes, ssh_port):
66
  """Modifies the node group settings and sets up iptable rules.
67

  
68
  For each pair of nodes add two rules that affect SSH connections from one
69
  to the other one.
70
  The first one redirects port 22 to some unused port so that connecting
71
  through 22 fails. The second redirects port `ssh_port` to port 22.
72
  Together this results in master seeing the SSH daemons on the nodes on
73
  `ssh_port` instead of 22.
74
  """
75
  default_ssh_port = netutils.GetDaemonPort(constants.SSH)
76
  all_nodes = qa_config.get("nodes")
77
  AssertCommand(["gnt-group", "modify",
78
                 "--node-parameters=ssh_port=" + str(ssh_port),
79
                 group])
80
  for node in nodes:
81
    ipt_rules.RedirectPort(node.primary, "localhost",
82
                           default_ssh_port, 65535)
83
    ipt_rules.RedirectPort(node.primary, "localhost",
84
                           ssh_port, default_ssh_port)
85
    for node2 in all_nodes:
86
      ipt_rules.RedirectPort(node2.primary, node.primary,
87
                             default_ssh_port, 65535)
88
      ipt_rules.RedirectPort(node2.primary, node.primary,
89
                             ssh_port, default_ssh_port)
90

  
91

  
44 92
def TestGroupAddRemoveRename():
45 93
  """gnt-group add/remove/rename"""
46 94
  existing_group_with_nodes = GetDefaultGroup()

Also available in: Unified diff