branching
Thierry Parmentelat [Fri, 23 May 2008 12:19:07 +0000 (12:19 +0000)]
system/TestApiserver.py
system/TestNode.py
system/TestPlc.py
system/config_main.py

index 1a82408..5459abf 100644 (file)
@@ -7,15 +7,18 @@ server_methods = [ ('GetNodes' ,  []),
                    ('AddNode' , True),
                    ('DeleteNode' , True),
                    ('UpdateNode' , True),
-                   ('AddNodeNetwork' , True),
-                   ('GetNodeNetworks' , True),
-                   ('GetNodeNetworkSettingTypes' , True),
-                   ('AddNodeNetworkSettingType' , True),
-                   ('AddNodeNetworkSetting' , True),
+                   ('AddInterface' , True),
+                   ('GetInterfaces' , True),
+                   ('GetInterfaceSettingTypes' , True),
+                   ('AddInterfaceSettingType' , True),
+                   ('AddInterfaceSetting' , True),
                    ('GetBootMedium' , True),
                    ('GetNodeGroups' , True),
                    ('AddNodeGroup' , True),
-                   ('AddNodeToNodeGroup' , True),
+                   ('GetNodeTagTypes' , True),
+                   ('AddNodeTagType', True),
+                   ('AddNodeTag', True),
+                   ('GetNodeTags', True),
                    ('AddInitScript' , True),
                    ('DeleteInitScript', True),
                    ('GetInitScripts', True),
index 5c2104e..7e822fd 100644 (file)
@@ -70,26 +70,26 @@ class TestNode:
         # create as reinstall to avoid user confirmation
         server.UpdateNode(userauth, self.name(), {'boot_state':'rins'})
         # populate network interfaces - primary
-        server.AddNodeNetwork(userauth,self.name(),
+        server.AddInterface(userauth,self.name(),
                                             self.node_spec['network_fields'])
         # populate network interfaces - others
         if self.node_spec.has_key('extra_interfaces'):
             for interface in self.node_spec['extra_interfaces']:
-                server.AddNodeNetwork(userauth,self.name(),
+                server.AddInterface(userauth,self.name(),
                                                     interface['network_fields'])
                 if interface.has_key('settings'):
                     for (attribute,value) in interface['settings'].iteritems():
                         # locate node network
-                        nn = server.GetNodeNetworks(userauth,{'ip':interface['network_fields']['ip']})[0]
+                        nn = server.GetInterfaces(userauth,{'ip':interface['network_fields']['ip']})[0]
                         nnid=nn['nodenetwork_id']
                         # locate or create node network attribute type
                         try:
-                            nnst = server.GetNodeNetworkSettingTypes(userauth,{'name':attribute})[0]
+                            nnst = server.GetInterfaceSettingTypes(userauth,{'name':attribute})[0]
                         except:
-                            nnst = server.AddNodeNetworkSettingType(rootauth,{'category':'test',
+                            nnst = server.AddInterfaceSettingType(rootauth,{'category':'test',
                                                                               'name':attribute})
                         # attach value
-                        server.AddNodeNetworkSetting(userauth,nnid,attribute,value)
+                        server.AddInterfaceSetting(userauth,nnid,attribute,value)
 
     def delete_node (self):
         # uses the right auth as far as poss.
index 6160262..095762a 100644 (file)
@@ -418,12 +418,40 @@ class TestPlc:
                         groups_dict[nodegroupname].append(test_node.name())
         auth=self.auth_root()
         for (nodegroupname,group_nodes) in groups_dict.iteritems():
-            try:
-                self.apiserver.GetNodeGroups(auth,{'name':nodegroupname})[0]
-            except:
-                self.apiserver.AddNodeGroup(auth,{'name':nodegroupname})
-            for node in group_nodes:
-                self.apiserver.AddNodeToNodeGroup(auth,node,nodegroupname)
+            print 'nodegroups:','dealing with nodegroup',nodegroupname,'on nodes',group_nodes
+            # first, check if the nodetagtype is here
+            tag_types = self.apiserver.GetNodeTagTypes(auth,{'name':nodegroupname})
+            if tag_types:
+                tag_type_id = tag_types[0]['node_tag_type_id']
+                print 'node-tag-type',nodegroupname,'already exists'
+            else:
+                tag_type_id = self.apiserver.AddNodeTagType(auth,
+                                                            {'name':nodegroupname,
+                                                             'description':
+                                                                 'for nodegroup %s'%nodegroupname,
+                                                             'category':'test',
+                                                             'min_role_id':10})
+            # create nodegroup
+            nodegroups = self.apiserver.GetNodeGroups (auth, {'groupname':nodegroupname})
+            if nodegroups:
+                print 'nodegroup',nodegroupname,'already exists'
+            else:
+                self.apiserver.AddNodeGroup(auth,
+                                            {'groupname': nodegroupname,
+                                             'node_tag_type_id': tag_type_id,
+                                             'value': 'yes'})
+            # set node tag on all nodes, value='yes'
+            for nodename in group_nodes:
+                # check if already set
+                # xxx need node_id - need improvement in the API
+                node_id = self.apiserver.GetNodes(auth,nodename)[0]['node_id']
+                node_tag = self.apiserver.GetNodeTags(auth,
+                                                      {'node_id':node_id,
+                                                       'node_tag_type_id':tag_type_id})
+                if node_tag:
+                    print 'node',nodename,'already has tag',nodegroupname
+                else:
+                    self.apiserver.AddNodeTag(auth, node_id, nodegroupname,"yes")
         return True
 
     def all_hostnames (self) :
index e0236b5..1346031 100644 (file)
@@ -13,6 +13,7 @@ def nodes(options):
                              'model':'qemu/minhw', } ,
              'host_box': 'testbox1.one-lab.org',
              'owner' : 'pi',
+             'nodegroups' : 'mynodegroup',
              'network_fields': { 'method':'static',
                                  'type':'ipv4',
                                  'ip':'xxx-deferred-xxx',