Revision a47f574c qa/qa_tags.py

b/qa/qa_tags.py
1
#
2
#
3

  
4 1
# Copyright (C) 2007 Google Inc.
5 2
#
6 3
# This program is free software; you can redistribute it and/or modify
......
24 21
"""
25 22

  
26 23
from ganeti import utils
24
from ganeti import constants
27 25

  
28 26
import qa_config
29 27
import qa_utils
28
import qa_rapi
30 29

  
31 30
from qa_utils import AssertEqual, StartSSH
32 31

  
......
34 33
_TEMP_TAG_NAMES = ["TEMP-Ganeti-QA-Tag%d" % i for i in range(3)]
35 34
_TEMP_TAG_RE = r'^TEMP-Ganeti-QA-Tag\d+$'
36 35

  
36
_KIND_TO_COMMAND = {
37
  constants.TAG_CLUSTER: "gnt-cluster",
38
  constants.TAG_NODE: "gnt-node",
39
  constants.TAG_INSTANCE: "gnt-instance",
40
  }
41

  
37 42

  
38
def _TestTags(cmdfn):
43
def _TestTags(kind, name):
39 44
  """Generic function for add-tags.
40 45

  
41 46
  """
42 47
  master = qa_config.GetMasterNode()
43 48

  
49
  def cmdfn(subcmd):
50
    cmd = [_KIND_TO_COMMAND[kind], subcmd]
51

  
52
    if kind != constants.TAG_CLUSTER:
53
      cmd.append(name)
54

  
55
    return cmd
56

  
44 57
  cmd = cmdfn('add-tags') + _TEMP_TAG_NAMES
45 58
  AssertEqual(StartSSH(master['primary'],
46 59
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
......
53 66
  AssertEqual(StartSSH(master['primary'],
54 67
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
55 68

  
69
  if qa_rapi.Enabled():
70
    qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)
71

  
56 72
  cmd = cmdfn('remove-tags') + _TEMP_TAG_NAMES
57 73
  AssertEqual(StartSSH(master['primary'],
58 74
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
......
61 77
@qa_utils.DefineHook('tags-cluster')
62 78
def TestClusterTags():
63 79
  """gnt-cluster tags"""
64
  _TestTags(lambda subcmd: ['gnt-cluster', subcmd])
80
  _TestTags(constants.TAG_CLUSTER, "")
65 81

  
66 82

  
67 83
@qa_utils.DefineHook('tags-node')
68 84
def TestNodeTags(node):
69 85
  """gnt-node tags"""
70
  _TestTags(lambda subcmd: ['gnt-node', subcmd, node['primary']])
86
  _TestTags(constants.TAG_NODE, node["primary"])
71 87

  
72 88

  
73 89
@qa_utils.DefineHook('tags-instance')
74 90
def TestInstanceTags(instance):
75 91
  """gnt-instance tags"""
76
  _TestTags(lambda subcmd: ['gnt-instance', subcmd, instance['name']])
92
  _TestTags(constants.TAG_INSTANCE, instance["name"])

Also available in: Unified diff