Exemple #1
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)
Exemple #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.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)