• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2"""
3The atomicgroup module contains the objects and methods used to
4manage atomic groups in Autotest.
5
6The valid actions are:
7create:  Create a new atomic group.
8delete:  Delete (invalidate) an existing atomic group.
9list:    Lists atomic groups.
10add:     Adds labels to an atomic group.
11remove:  Removes labels from an atomic group.
12
13See topic_common.py for a High Level Design and Algorithm.
14"""
15
16import os, sys
17from autotest_lib.cli import topic_common, action_common
18
19class atomicgroup(topic_common.atest):
20    """
21    Atomic group class
22
23    atest atomicgroup [create|delete|list|add|remove] <options>
24    """
25    usage_action = '[create|delete|list|add|remove]'
26    topic = 'atomic_group'
27    msg_topic = 'atomicgroup'
28    msg_items = '<atomicgroups>'
29
30
31    def __init__(self):
32        super(atomicgroup, self).__init__()
33        self.parser.add_option('-G', '--glist',
34                               help='File listing the ATOMIC GROUPs',
35                               type='string', default=None,
36                               metavar='ATOMIC_GROUP_FLIST')
37
38        self.topic_parse_info = topic_common.item_parse_info(
39            attribute_name='atomicgroups',
40            filename_option='glist',
41            use_leftover=True)
42
43
44    def get_items(self):
45        return self.atomicgroups
46
47
48class atomicgroup_help(atomicgroup):
49    """Just to get the atest logic working.  Usage is set by its parent."""
50    pass
51
52
53class atomicgroup_list(action_common.atest_list, atomicgroup):
54    """atest atomicgroup list [--show-invalid]"""
55    def __init__(self):
56        super(atomicgroup_list, self).__init__()
57        self.parser.add_option('-d', '--show-invalid',
58                               help='Don\'t hide invalid atomic groups.',
59                               action='store_true')
60
61
62    def parse(self):
63        options, leftover = super(atomicgroup_list, self).parse()
64        self.show_invalid = options.show_invalid
65        return options, leftover
66
67
68    def execute(self):
69        return super(atomicgroup_list, self).execute(op='get_atomic_groups')
70
71
72    def output(self, results):
73        if not self.show_invalid:
74            results = [atomicgroup for atomicgroup in results
75                       if not atomicgroup['invalid']]
76
77        keys = ['name', 'description', 'max_number_of_machines', 'invalid']
78        super(atomicgroup_list, self).output(results, keys)
79
80
81class atomicgroup_create(action_common.atest_create, atomicgroup):
82    def __init__(self):
83        super(atomicgroup_create, self).__init__()
84        self.parser.add_option('-n', '--max_number_of_machines',
85                               help='Maximum # of machines for this group.',
86                               type='int', default=None)
87        self.parser.add_option('-d', '--description',
88                               help='Description of this atomic group.',
89                               type='string', default='')
90
91
92    def parse(self):
93        options, leftover = super(atomicgroup_create, self).parse()
94        self.data_item_key = 'name'
95        self.data['description'] = options.description
96        self.data['max_number_of_machines'] = options.max_number_of_machines
97        return options, leftover
98
99
100class atomicgroup_delete(action_common.atest_delete, atomicgroup):
101    """atest atomicgroup delete <atomicgroup>"""
102    pass
103
104
105class atomicgroup_add_or_remove(atomicgroup):
106
107    def __init__(self):
108        super(atomicgroup_add_or_remove, self).__init__()
109        # .add_remove_things is used by action_common.atest_add_or_remove.
110        self.add_remove_things = {'labels': 'label'}
111        lower_words = tuple(word.lower() for word in self.usage_words)
112        self.parser.add_option('-l', '--label',
113                               help=('%s LABELS(s) %s the ATOMIC GROUP.' %
114                                     self.usage_words),
115                               type='string',
116                               metavar='LABEL')
117        self.parser.add_option('-L', '--label_list',
118                               help='File containing LABELs to %s %s '
119                               'the ATOMIC GROUP.' % lower_words,
120                               type='string',
121                               metavar='LABEL_FLIST')
122
123
124    def parse(self):
125        label_info = topic_common.item_parse_info(attribute_name='labels',
126                                                  inline_option='label',
127                                                  filename_option='label_list')
128
129        options, leftover = super(atomicgroup_add_or_remove,
130                                  self).parse([label_info],
131                                              req_items='atomicgroups')
132        if not getattr(self, 'labels', None):
133            self.invalid_syntax('%s %s requires at least one label' %
134                                (self.msg_topic,
135                                 self.usage_action))
136        return options, leftover
137
138
139class atomicgroup_add(action_common.atest_add, atomicgroup_add_or_remove):
140    """atest atomicgroup add <atomicgroup>
141     [--label <label>] [--label_list <file>]"""
142    pass
143
144
145class atomicgroup_remove(action_common.atest_remove, atomicgroup_add_or_remove):
146    """atest atomicgroup remove <atomicgroup>
147     [--label <label>] [--label_list <file>]"""
148    pass
149