Ejemplo n.º 1
0
    def test_deplyments_get_devices(self):
        """Create deployments, get devices with pagination"""
        devices = []
        devices_qty = 30
        device_ids = []
        default_per_page = 20
        device_type = "test-hammer-type"

        # create devices
        for i in range(0, devices_qty):
            device = Device(device_type)
            self.inventory_add_dev(device)
            devices.append(device)
            device_ids.append(device.devid)

        data = b"foo_bar"
        artifact_name = "pagination-test-" + str(uuid4())
        # come up with an artifact
        with artifact_from_data(name=artifact_name,
                                data=data,
                                devicetype=device_type) as art:
            ac = SimpleArtifactsClient()
            ac.add_artifact(description="some description",
                            size=art.size,
                            data=art)

            new_dep = self.d.make_new_deployment(name="pagination deployment",
                                                 artifact_name=artifact_name,
                                                 devices=device_ids)
            dep_id = self.d.add_deployment(new_dep)

            for dev in devices:
                dc = SimpleDeviceClient()
                dc.get_next_deployment(
                    dev.fake_token,
                    artifact_name="different {}".format(artifact_name),
                    device_type=dev.device_type,
                )

            # check default 'page' and 'per_page' values
            res = self.d.client.Management_API.List_Devices_in_Deployment_with_pagination(
                Authorization="foo", deployment_id=dep_id).result()[0]
            assert len(res) == default_per_page

            # check custom 'per_page'
            res = self.d.client.Management_API.List_Devices_in_Deployment_with_pagination(
                Authorization="foo",
                deployment_id=dep_id,
                per_page=devices_qty).result()[0]
            assert len(res) == devices_qty

            # check 2nd page
            devices_qty_on_second_page = devices_qty - default_per_page
            res = self.d.client.Management_API.List_Devices_in_Deployment_with_pagination(
                Authorization="foo",
                deployment_id=dep_id,
                page=2,
                per_page=default_per_page).result()[0]
            assert len(res) == devices_qty_on_second_page
Ejemplo n.º 2
0
    def test_deployments_new_valid(self):
        """Add a new valid deployment, verify its status, verify device deployment
        status, abort and verify eveything once again"""
        dev = Device()

        self.log.info('fake device with ID: %s', dev.devid)

        self.inventory_add_dev(dev)

        data = b'foo_bar'
        artifact_name = 'hammer-update-' + str(uuid4())
        # come up with an artifact
        with artifact_from_data(name=artifact_name, data=data, devicetype=dev.device_type) as art:
            ac = SimpleArtifactsClient()
            artid = ac.add_artifact(description='some description', size=art.size,
                                    data=art)

            newdep = self.make_new_deployment(name='fake deployment', artifact_name=artifact_name,
                                              devices=[dev.devid])
            depid = self.add_deployment(newdep)

            # artifact is used in deployment, so attempts to remove it should
            # fail
            try:
                ac.delete_artifact(artid)
            except ArtifactsClientError as ace:
                #  artifact is used in deployment
                assert ace.response.status_code == 409
            else:
                raise AssertionError('expected to fail')

            dep = self.client.deployments.get_deployments_id(Authorization='foo',
                                                             id=depid).result()[0]
            self.log.debug('deployment dep: %s', dep)
            assert dep.artifact_name == artifact_name
            assert dep.id == depid
            assert dep.status == 'pending'

            # fetch device status
            depdevs = self.client.deployments.get_deployments_deployment_id_devices(Authorization='foo',
                                                                         deployment_id=depid).result()[0]
            self.log.debug('deployment devices: %s', depdevs)
            assert len(depdevs) == 1
            depdev = depdevs[0]
            assert depdev.status == 'pending'
            assert depdev.id == dev.devid

            # verify statistics
            self.verify_deployment_stats(depid, expected={
                'pending': 1,
            })

            # abort deployment
            self.abort_deployment(depid)

            # that it's 'finished' now
            aborted_dep = self.client.deployments.get_deployments_id(Authorization='foo',
                                                             id=depid).result()[0]
            self.log.debug('deployment dep: %s', aborted_dep)
            assert aborted_dep.status == 'finished'

            # verify statistics once again
            self.verify_deployment_stats(depid, expected={
                'aborted': 1,
            })

            # fetch device status
            depdevs = self.client.deployments.get_deployments_deployment_id_devices(Authorization='foo',
                                                                         deployment_id=depid).result()[0]
            self.log.debug('deployment devices: %s', depdevs)
            assert len(depdevs) == 1
            depdev = depdevs[0]
            assert depdev.status == 'aborted'

            # deleting artifact should succeed
            ac.delete_artifact(artid)
Ejemplo n.º 3
0
    def test_deployments_new_valid(self):
        """Add a new valid deployment, verify its status, verify device deployment
        status, abort and verify eveything once again"""
        dev = Device()

        self.d.log.info("fake device with ID: %s", dev.devid)

        self.inventory_add_dev(dev)

        data = b"foo_bar"
        artifact_name = "hammer-update-" + str(uuid4())
        # come up with an artifact
        with artifact_from_data(name=artifact_name,
                                data=data,
                                devicetype=dev.device_type) as art:
            ac = SimpleArtifactsClient()
            artid = ac.add_artifact(description="some description",
                                    size=art.size,
                                    data=art)

            newdep = self.d.make_new_deployment(name="fake deployment",
                                                artifact_name=artifact_name,
                                                devices=[dev.devid])
            depid = self.d.add_deployment(newdep)

            # artifact is used in deployment, so attempts to remove it should
            # fail
            try:
                ac.delete_artifact(artid)
            except ArtifactsClientError as ace:
                #  artifact is used in deployment
                assert ace.response.status_code == 409
            else:
                raise AssertionError("expected to fail")

            dc = SimpleDeviceClient()
            nextdep = dc.get_next_deployment(
                dev.fake_token,
                artifact_name="different {}".format(artifact_name),
                device_type=dev.device_type,
            )

            dep = self.d.client.Management_API.Show_Deployment(
                Authorization="foo", id=depid).result()[0]
            assert dep.artifact_name == artifact_name
            assert dep.id == depid
            assert dep.status == "pending"

            # fetch device status
            depdevs = self.d.client.Management_API.List_Devices_in_Deployment(
                Authorization="foo", deployment_id=depid).result()[0]
            assert len(depdevs) == 1
            depdev = depdevs[0]
            assert depdev.status == "pending"
            assert depdev.id == dev.devid

            # verify statistics
            self.d.verify_deployment_stats(depid, expected={"pending": 1})

            # abort deployment
            self.d.abort_deployment(depid)

            # that it's 'finished' now
            aborted_dep = self.d.client.Management_API.Show_Deployment(
                Authorization="foo", id=depid).result()[0]
            self.d.log.debug("deployment dep: %s", aborted_dep)
            assert aborted_dep.status == "finished"

            # verify statistics once again
            self.d.verify_deployment_stats(depid, expected={"aborted": 1})

            # fetch device status
            depdevs = self.d.client.Management_API.List_Devices_in_Deployment(
                Authorization="foo", deployment_id=depid).result()[0]
            self.d.log.debug("deployment devices: %s", depdevs)
            assert len(depdevs) == 1
            depdev = depdevs[0]
            assert depdev.status == "aborted"

            # deleting artifact should succeed
            ac.delete_artifact(artid)