예제 #1
0
    def _get_action_context(self, action_id, design_ref):
        """Create the action-specific context items for template rendering.

        :param action_id: ULID of this boot action
        :param design_ref: Design reference representing the site design
        """
        return dict(key=ulid2.ulid_to_base32(action_id),
                    report_url=config.config_mgr.conf.bootactions.report_url,
                    design_ref=design_ref)
예제 #2
0
    def render(self, nodename, site_design, action_id, design_ref):
        """Render this asset into a base64 encoded string.

        The ``nodename`` and ``action_id`` will be used to construct
        the context for evaluating the ``template`` pipeline segment

        :param nodename: the name of the node where the asset will be deployed
        :param site_design: instance of objects.SiteDesign
        :param action_id: a 128-bit ULID boot action id
        :param design_ref: The design ref this bootaction was initiated under
        """
        node = site_design.get_baremetal_node(nodename)

        tpl_ctx = {
            'node': {
                'hostname': nodename,
                'tags': [t for t in node.tags],
                'labels': {k: v
                           for (k, v) in node.owner_data.items()},
                'network': {},
            },
            'action': {
                'key': ulid2.ulid_to_base32(action_id),
                'report_url': config.config_mgr.conf.bootactions.report_url,
                'design_ref': design_ref,
            }
        }

        for a in node.addressing:
            if a.address is not None:
                tpl_ctx['node']['network'][a.network] = dict()
                tpl_ctx['node']['network'][a.network]['ip'] = a.address
                network = site_design.get_network(a.network)
                tpl_ctx['node']['network'][a.network]['cidr'] = network.cidr
                tpl_ctx['node']['network'][
                    a.network]['dns_suffix'] = network.dns_domain

        if self.location is not None:
            rendered_location = self.execute_pipeline(self.location,
                                                      self.location_pipeline,
                                                      tpl_ctx=tpl_ctx)
            data_block = self.resolve_asset_location(rendered_location)
        else:
            data_block = self.data.encode('utf-8')

        value = self.execute_pipeline(data_block,
                                      self.data_pipeline,
                                      tpl_ctx=tpl_ctx)

        if isinstance(value, str):
            value = value.encode('utf-8')
        self.rendered_bytes = value
    def test_bootaction_render_key(self, input_files, deckhand_ingester,
                                   setup):
        """Test that a bootaction can render the correct action_id and
           action_key needed by the signalling API."""
        input_file = input_files.join("deckhand_fullsite.yaml")

        design_state = DrydockState()
        design_ref = "file://%s" % str(input_file)

        design_status, design_data = deckhand_ingester.ingest_data(
            design_state=design_state, design_ref=design_ref)

        ba = design_data.get_bootaction('helloworld')
        action_id = ulid2.generate_binary_ulid()
        action_key = os.urandom(32)
        assets = ba.render_assets('compute01', design_data, action_id,
                                  action_key, design_ref)

        assert action_key.hex() in assets[2].rendered_bytes.decode('utf-8')
        assert ulid2.ulid_to_base32(
            action_id) in assets[2].rendered_bytes.decode('utf-8')
예제 #4
0
def test_conversion_roundtrip():
    ulid = generate_binary_ulid()
    encoded = ulid_to_base32(ulid)
    uuid = ulid_to_uuid(ulid)
    assert ulid_to_binary(uuid) == ulid_to_binary(ulid)
    assert ulid_to_binary(encoded) == ulid_to_binary(ulid)