qa_tags.py 2.13 KB
Newer Older
1 2 3
#
#

Michael Hanselmann's avatar
Michael Hanselmann committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Copyright (C) 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


"""Tags related QA tests.

"""

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
26
from ganeti import constants
Michael Hanselmann's avatar
Michael Hanselmann committed
27

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
28
import qa_rapi
Michael Hanselmann's avatar
Michael Hanselmann committed
29

Iustin Pop's avatar
Iustin Pop committed
30
from qa_utils import AssertCommand
Michael Hanselmann's avatar
Michael Hanselmann committed
31 32 33 34 35


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

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
36 37 38 39
_KIND_TO_COMMAND = {
  constants.TAG_CLUSTER: "gnt-cluster",
  constants.TAG_NODE: "gnt-node",
  constants.TAG_INSTANCE: "gnt-instance",
40
  constants.TAG_NODEGROUP: "gnt-group",
Hrvoje Ribicic's avatar
Hrvoje Ribicic committed
41
  constants.TAG_NETWORK: "gnt-network",
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
42 43
  }

Michael Hanselmann's avatar
Michael Hanselmann committed
44

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
45
def _TestTags(kind, name):
Michael Hanselmann's avatar
Michael Hanselmann committed
46 47 48
  """Generic function for add-tags.

  """
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
49 50 51 52 53 54 55 56
  def cmdfn(subcmd):
    cmd = [_KIND_TO_COMMAND[kind], subcmd]

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

    return cmd

Iustin Pop's avatar
Iustin Pop committed
57 58 59 60 61 62 63
  for cmd in [
    cmdfn("add-tags") + _TEMP_TAG_NAMES,
    cmdfn("list-tags"),
    ["gnt-cluster", "search-tags", _TEMP_TAG_RE],
    cmdfn("remove-tags") + _TEMP_TAG_NAMES,
    ]:
    AssertCommand(cmd)
Michael Hanselmann's avatar
Michael Hanselmann committed
64

65 66 67
  if qa_rapi.Enabled():
    qa_rapi.TestTags(kind, name, _TEMP_TAG_NAMES)

Michael Hanselmann's avatar
Michael Hanselmann committed
68 69 70

def TestClusterTags():
  """gnt-cluster tags"""
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
71
  _TestTags(constants.TAG_CLUSTER, "")
Michael Hanselmann's avatar
Michael Hanselmann committed
72 73 74 75


def TestNodeTags(node):
  """gnt-node tags"""
76
  _TestTags(constants.TAG_NODE, node.primary)
Michael Hanselmann's avatar
Michael Hanselmann committed
77 78


79 80 81 82 83
def TestGroupTags(group):
  """gnt-group tags"""
  _TestTags(constants.TAG_NODEGROUP, group)


Michael Hanselmann's avatar
Michael Hanselmann committed
84 85
def TestInstanceTags(instance):
  """gnt-instance tags"""
86
  _TestTags(constants.TAG_INSTANCE, instance.name)
Hrvoje Ribicic's avatar
Hrvoje Ribicic committed
87 88 89 90 91


def TestNetworkTags(network):
  """gnt-network tags"""
  _TestTags(constants.TAG_NETWORK, network)