예제 #1
0
    def test_protobufConversion(self):
        """Tests conversion between json and protobuf configuration representations."""

        # Convert json data to protobuf format
        with open (configFilePath, "r") as jsonFile:
            configData = json.load(jsonFile)
        #protobuf = self.nodeConfig.toProtoBuf(configData)
        protobuf = NodeConfig.toProtoBuf(configData)

        # Convert back to json representation
        #fromProtobuf = self.nodeConfig.fromProtoBuf(protobuf.SerializeToString())
        fromProtobuf = NodeConfig.fromProtoBuf(protobuf.SerializeToString())
        
        # Hash config instance from conversion and compare to initial configuration
        nc_protobuf = NodeConfig(configData=fromProtobuf)

        assert(self.nodeConfig.calculateHash() == nc_protobuf.calculateHash())
예제 #2
0
    def loadConfig(self, newConfig, hashValue):
        '''Verify and queue new configuration for loading.'''

        # Convert from protobuf to json
        jsonConfig = NodeConfig.fromProtoBuf(newConfig)
        jsonConfig['node'][
            'nodeId'] = self.config.nodeId  # Don't overwrite node id via update

        # Create, verify, and store new configuration
        newConfig = NodeConfig(configData=jsonConfig)

        if (newConfig.calculateHash() == hashValue
                and newConfig.loadSuccess):  # configuration verified
            #self.newConfig = newConfig
            return [True, newConfig]
        else:
            #self.newConfig = None
            return [False, None]