예제 #1
0
    def test_build_data_select_latest(self, blank_state):
        """Test that build data can be selected for only latest instance."""
        build_data_latest = {
            'node_name': 'foo',
            'generator': 'hello_world',
            'data_format': 'text/plain',
            'data_element': 'Hello World!',
            'task_id': uuid.uuid4(),
            'collected_date': datetime.utcnow(),
        }

        build_data_old = copy.deepcopy(build_data_latest)
        build_data_old['collected_date'] = build_data_latest[
            'collected_date'] - timedelta(days=1)
        build_data_old['task_id'] = uuid.uuid4()

        build_data1 = objects.BuildData(**build_data_latest)
        build_data2 = objects.BuildData(**build_data_old)

        result = blank_state.post_build_data(build_data1)

        assert result

        result = blank_state.post_build_data(build_data2)

        assert result

        bd_list = blank_state.get_build_data(node_name='foo', latest=True)

        assert len(bd_list) == 1

        assert bd_list[0].to_dict() == build_data1.to_dict()
예제 #2
0
 def side_effect(**kwargs):
     build_data = objects.BuildData(node_name="test",
                                    task_id="tid",
                                    generator="lshw",
                                    data_format="text/plain",
                                    data_element="<mocktest></mocktest>")
     return [build_data]
예제 #3
0
 def side_effect(**kwargs):
     build_data = objects.BuildData(node_name="controller01",
                                    task_id="tid",
                                    generator="lshw",
                                    data_format="text/plain",
                                    data_element=xml_example)
     return [build_data]
예제 #4
0
    def test_build_data_insert_no_collected_date(self, blank_state):
        """Test that build data can be inserted omitting collection date."""
        build_data_fields = {
            'node_name': 'foo',
            'generator': 'hello_world',
            'data_format': 'text/plain',
            'data_element': 'Hello World!',
            'task_id': uuid.uuid4(),
        }

        build_data = objects.BuildData(**build_data_fields)

        result = blank_state.post_build_data(build_data)

        assert result
예제 #5
0
        def seed_build_data(nodelist=['foo'],
                            tasklist=None,
                            generatorlist=None,
                            count=1,
                            random_dates=True):
            """Seed the database with ``count`` build data elements for each node.

            If tasklist is specified, it should be a list of length ``count`` such that
            as build_data are added for a node, each task_id will be used one for each node

            :param nodelist: list of string nodenames for build data
            :param tasklist: list of uuid.UUID IDs for task. If omitted, uuids will be generated
            :param gneratorlist: list of string generatos to assign to build data. If omitted, 'hello_world'
                                 is used.
            :param count: number build data elements to create for each node
            :param random_dates: whether to generate random dates in the past 180 days or create each
                                 build data element with utcnow()
            """
            for n in nodelist:
                for i in range(count):
                    if random_dates:
                        collected_date = datetime.datetime.utcnow(
                        ) - datetime.timedelta(days=random.randint(1, 180))
                    else:
                        collected_date = None
                    if tasklist:
                        task_id = tasklist[i]
                    else:
                        task_id = uuid.uuid4()
                    if generatorlist:
                        generator = generatorlist[i]
                    else:
                        generator = 'hello_world'
                    bd = objects.BuildData(node_name=n,
                                           task_id=task_id,
                                           generator=generator,
                                           data_format='text/plain',
                                           collected_date=collected_date,
                                           data_element='Hello World!')
                    blank_state.post_build_data(bd)
                    i = i + 1
예제 #6
0
    def test_build_data_select(self, blank_state):
        """Test that build data can be deserialized from the database."""
        build_data_fields = {
            'node_name': 'foo',
            'generator': 'hello_world',
            'data_format': 'text/plain',
            'data_element': 'Hello World!',
            'task_id': uuid.uuid4(),
            'collected_date': datetime.utcnow(),
        }

        build_data = objects.BuildData(**build_data_fields)

        result = blank_state.post_build_data(build_data)

        assert result

        bd_list = blank_state.get_build_data()

        assert len(bd_list) == 1

        assert bd_list[0].to_dict() == build_data.to_dict()
예제 #7
0
    def test_read_tasks_builddata(self, falcontest, blank_state,
                                  deckhand_orchestrator):
        """Test that the tasks API includes build data when prompted."""
        req_hdr = {
            'Content-Type': 'application/json',
            'X-IDENTITY-STATUS': 'Confirmed',
            'X-USER-NAME': 'Test',
            'X-ROLES': 'admin',
        }
        # Seed DB with a task
        ctx = DrydockRequestContext()
        task = deckhand_orchestrator.create_task(
            action=hd_fields.OrchestratorAction.PrepareNodes,
            design_ref='http://foo.com',
            context=ctx)

        # Seed DB with build data for task
        build_data = objects.BuildData(node_name='foo',
                                       task_id=task.get_id(),
                                       generator='hello_world',
                                       data_format='text/plain',
                                       data_element='Hello World!')
        blank_state.post_build_data(build_data)

        url = '/api/v1.0/tasks/%s' % str(task.get_id())

        resp = falcontest.simulate_get(url,
                                       headers=req_hdr,
                                       query_string="builddata=true")

        assert resp.status == falcon.HTTP_200

        resp_body = resp.json

        assert isinstance(resp_body.get('build_data'), list)

        assert len(resp_body.get('build_data')) == 1