Merge branch 'upstreammaster'
[sfa.git] / sfa / rspecs / versions / sfav1.py
index 8f172bd..ab022df 100644 (file)
@@ -93,6 +93,7 @@ class SFAv1(BaseVersion):
         attributes = []
         nodes_with_slivers = self.get_nodes_with_slivers()
         for default_attribute in self.get_default_sliver_attributes(network):
+            attribute = default_attribute.copy()
             attribute['node_id'] = None
             attributes.append(attribute)
         for node in nodes_with_slivers:
@@ -100,7 +101,7 @@ class SFAv1(BaseVersion):
             sliver_attributes = self.get_sliver_attributes(nodename, network)
             for sliver_attribute in sliver_attributes:
                 sliver_attribute['node_id'] = nodename
-                attributes.append(attribute)
+                attributes.append(sliver_attribute)
         return attributes
 
 
@@ -114,7 +115,7 @@ class SFAv1(BaseVersion):
                 SFAv1Sliver.add_sliver_attribute(sliver, name, value)
         else:
             # should this be an assert / raise an exception?
-            print "WARNING: failed to find component_id", component_id
+            logger.error("WARNING: failed to find component_id %s" % component_id)
 
     def get_sliver_attributes(self, component_id, network=None):
         nodes = self.get_nodes({'component_id': '*%s*' % component_id})
@@ -139,9 +140,12 @@ class SFAv1(BaseVersion):
         if network:
             defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network)
         else:
-            defaults = self.xml.xpath("//sliver_defaults" % network)
-        if not defaults :
-            network_tag = self.xml.xpath("//network[@name='%s']" % network)
+            defaults = self.xml.xpath("//sliver_defaults")
+        if not defaults:
+            if network:
+                network_tag = self.xml.xpath("//network[@name='%s']" % network)
+            else:
+                network_tag = self.xml.xpath("//network")    
             if isinstance(network_tag, list):
                 network_tag = network_tag[0]
             defaults = network_tag.add_element('sliver_defaults')
@@ -191,6 +195,9 @@ class SFAv1(BaseVersion):
         Merge contents for specified rspec with current rspec
         """
 
+        if not in_rspec:
+            return
+
         from sfa.rspecs.rspec import RSpec
         if isinstance(in_rspec, RSpec):
             rspec = in_rspec