def get_nodes_instances(self, cloud_service_name=None):
        '''Return dict {<node_instance_name>: NodeInstance, }
        '''
        nodes_instances = {}

        self._retrieveAndSetRun()

        nodes_instances_runtime_parameters = \
            DomExtractor.extract_nodes_instances_runtime_parameters(self.run_dom, cloud_service_name)

        nodes_runtime_parameters = DomExtractor.extract_nodes_runtime_parameters(self.run_dom)

        for node_instance_name, node_instance_runtime_parameters in nodes_instances_runtime_parameters.items():

            node_instance = NodeInstance(node_instance_runtime_parameters)
            node_name = node_instance.get_node_name()

            if nodes_runtime_parameters:
                node_runtime_parameters = nodes_runtime_parameters.get(node_name, {})
                if node_runtime_parameters:
                    node_instance.set_parameter(NodeDecorator.MAX_PROVISIONING_FAILURES_KEY,
                        node_runtime_parameters.get(NodeDecorator.MAX_PROVISIONING_FAILURES_KEY, '0'))

            image_attributes = DomExtractor.extract_node_image_attributes(self.run_dom, node_name)
            node_instance.set_image_attributes(image_attributes)

            image_targets = DomExtractor.extract_node_image_targets(self.run_dom, node_name)
            node_instance.set_image_targets(image_targets)

            build_state = DomExtractor.extract_node_image_build_state(self.run_dom, node_name)
            node_instance.set_build_state(build_state)

            nodes_instances[node_instance_name] = node_instance

        return nodes_instances
Exemplo n.º 2
0
    def test_get_disk_attach_detach(self):
        ni = NodeInstance()
        assert None == ni.get_disk_attach_size()
        assert None == ni.get_disk_detach_device()

        ni = NodeInstance()
        ni.set_parameter(NodeDecorator.SCALE_DISK_ATTACH_SIZE, 1)
        assert 1 == ni.get_disk_attach_size()
        ni.set_parameter(NodeDecorator.SCALE_DISK_DETACH_DEVICE, 'foo')
        assert 'foo' == ni.get_disk_detach_device()
    def test_get_disk_attach_detach(self):
        ni = NodeInstance()
        assert None == ni.get_disk_attach_size()
        assert None == ni.get_disk_detach_device()

        ni = NodeInstance()
        ni.set_parameter(NodeDecorator.SCALE_DISK_ATTACH_SIZE, 1)
        assert 1 == ni.get_disk_attach_size()
        ni.set_parameter(NodeDecorator.SCALE_DISK_DETACH_DEVICE, 'foo')
        assert 'foo' == ni.get_disk_detach_device()
    def setUp(self):
        cloudName = TestOkeanosClientCloud.CLOUD_NAME
        flavorKey = TestOkeanosClientCloud.FLAVOR_KEY
        resizeFlavorKey = TestOkeanosClientCloud.RESIZE_FLAVOR_KEY

        os.environ['SLIPSTREAM_CONNECTOR_INSTANCE'] = cloudName
        os.environ['SLIPSTREAM_BOOTSTRAP_BIN'] = 'http://example.com/bootstrap'
        os.environ['SLIPSTREAM_DIID'] = \
            '%s-1234-1234-1234-123456789012' % str(int(time.time()))[2:]

        if not os.path.exists(CONFIG_FILE):
            raise Exception('Configuration file %s not found.' % CONFIG_FILE)

        self.ch = ConfigHolder(configFile=CONFIG_FILE, context={'foo': 'bar'})
        self.ch.verboseLevel = int(self.ch.verboseLevel)

        flavor = self.ch.config[flavorKey]
        resizeFlavor = self.ch.config[resizeFlavorKey]
        self.log("Initial Flavor: '%s' = %s" % (flavorKey, flavor))
        self.log("Resize  Flavor: '%s' = %s" % (resizeFlavorKey, resizeFlavor))

        self.user_info = UserInfo(cloudName)
        self.user_info['General.ssh.public.key'] = self.ch.config['General.ssh.public.key']
        self.user_info[cloudName + '.endpoint'] = self.ch.config[cloudName + '.auth_url']
        self.user_info[cloudName + '.username'] = self.ch.config[cloudName + '.user.uuid']
        self.user_info[cloudName + '.password'] = self.ch.config[cloudName + '.token']
        self.user_info[cloudName + '.project.id'] = self.ch.config[cloudName + '.project.id']

        node_name = 'test_node'

        self.multiplicity = int(self.ch.config['multiplicity'])

        self.node_instances = {}
        for i in range(1, self.multiplicity + 1):
            node_instance_name = node_name + '.' + str(i)
            ni = NodeInstance({
                NodeDecorator.NODE_NAME_KEY: node_name,
                NodeDecorator.NODE_INSTANCE_NAME_KEY: node_instance_name,
                'cloudservice': cloudName,
                'image.description': 'This is a test image.',
                'image.platform': self.ch.config[cloudName + '.image.platform'],
                'image.id': self.ch.config[cloudName + '.imageid'],
                flavorKey: flavor,
                resizeFlavorKey: resizeFlavor,
                'network': self.ch.config['network']
            })
            ni.set_parameter(NodeDecorator.SCALE_DISK_ATTACH_SIZE, 1)
            self.node_instances[node_instance_name] = ni

        self.node_instance = NodeInstance({
            NodeDecorator.NODE_NAME_KEY: node_name,
            NodeDecorator.NODE_INSTANCE_NAME_KEY: NodeDecorator.MACHINE_NAME,
            'cloudservice': cloudName,
            'disk.attach.size': self.ch.config[cloudName + '.disk.attach.size'],
            'image.description': 'This is a test image.',
            'image.platform': self.ch.config[cloudName + '.image.platform'],
            'image.loginUser': self.ch.config[cloudName + '.image.loginuser'],
            'image.id': self.ch.config[cloudName + '.imageid'],
            flavorKey: flavor,
            resizeFlavorKey: resizeFlavor,
            'network': self.ch.config['network'],
            'image.prerecipe':
"""#!/bin/sh
set -e
set -x

ls -l /tmp
dpkg -l | egrep "nano|lvm" || true
""",
                'image.packages': ['lvm2', 'nano'],
                'image.recipe':
"""#!/bin/sh
set -e
set -x

dpkg -l | egrep "nano|lvm" || true
lvs
"""
        })