Exemple #1
0
    def test_get_server_dependent_resources(self, mock_volume_list):
        plugin = VolumeProtectablePlugin(self._context)

        attached = [{'server_id': 'abcdef', 'name': 'name'}]
        mock_volume_list.return_value = [
            vol_info('123', attached, 'name123'),
            vol_info('456', [], 'name456'),
        ]
        self.assertEqual([Resource('OS::Cinder::Volume', '123', 'name123')],
                         plugin.get_dependent_resources(
                             self._context,
                             Resource("OS::Nova::Server", 'abcdef', 'name')))
Exemple #2
0
    def test_get_project_dependent_resources(self, mock_volume_list):
        project = project_info('abcd', constants.PROJECT_RESOURCE_TYPE,
                               'nameabcd')
        plugin = VolumeProtectablePlugin(self._context)

        volumes = [
            mock.Mock(name='Volume', id='123'),
            mock.Mock(name='Volume', id='456'),
        ]
        setattr(volumes[0], 'os-vol-tenant-attr:tenant_id', 'abcd')
        setattr(volumes[1], 'os-vol-tenant-attr:tenant_id', 'efgh')
        setattr(volumes[0], 'name', 'name123')
        setattr(volumes[1], 'name', 'name456')

        mock_volume_list.return_value = volumes
        self.assertEqual(
            plugin.get_dependent_resources(self._context, project),
            [Resource('OS::Cinder::Volume', '123', 'name123')])
    def test_get_pod_dependent_resources(self, mock_pod_read, mock_pvc_read,
                                         mock_pv_read, mock_volume_list):
        plugin = VolumeProtectablePlugin(self._context)

        pod = V1Pod(api_version="v1",
                    kind="Pod",
                    metadata=V1ObjectMeta(
                        name="busybox-test",
                        namespace="default",
                        uid="dd8236e1-8c6c-11e7-9b7a-fa163e18e097"),
                    spec=V1PodSpec(volumes=[
                        V1Volume(persistent_volume_claim=(
                            V1PersistentVolumeClaimVolumeSource(
                                claim_name="cinder-claim1'")))
                    ]),
                    status=V1PodStatus(phase="Running"))

        pvc = V1PersistentVolumeClaim(
            api_version="v1",
            kind="PersistentVolumeClaim",
            metadata=V1ObjectMeta(name="cinder-claim1",
                                  namespace="default",
                                  uid="fec036b7-9123-11e7-a930-fa163e18e097"),
            spec=V1PersistentVolumeClaimSpec(
                access_modes=["ReadWriteOnce"],
                volume_name="pvc-fec036b7-9123-11e7-a930-fa163e18e097"),
            status=V1PersistentVolumeClaimStatus(phase="Bound"))

        pv = V1PersistentVolume(
            api_version="v1",
            kind="PersistentVolume",
            metadata=V1ObjectMeta(
                name="pvc-fec036b7-9123-11e7-a930-fa163e18e097",
                namespace="None",
                uid="ff43c217-9123-11e7-a930-fa163e18e097"),
            spec=V1PersistentVolumeSpec(cinder=V1CinderVolumeSource(
                fs_type=None,
                read_only=None,
                volume_id="7daedb1d-fc99-4a35-ab1b-b64971271d17")),
            status=V1PersistentVolumeClaimStatus(phase="Bound"))

        volumes = [
            mock.Mock(name='Volume',
                      id='7daedb1d-fc99-4a35-ab1b-b64971271d17',
                      availability_zone='az1'),
            mock.Mock(name='Volume',
                      id='7daedb1d-fc99-4a35-ab1b-b64922441d17',
                      availability_zone='az1'),
        ]
        setattr(volumes[0], 'name', 'name123')
        setattr(volumes[1], 'name', 'name456')

        mock_pod_read.return_value = pod
        mock_pvc_read.return_value = pvc
        mock_pv_read.return_value = pv
        mock_volume_list.return_value = volumes
        self.assertEqual([
            Resource('OS::Cinder::Volume',
                     '7daedb1d-fc99-4a35-ab1b-b64971271d17', 'name123',
                     {'availability_zone': 'az1'})
        ],
                         plugin.get_dependent_resources(
                             self._context,
                             Resource(
                                 id="c88b92a8-e8b4-504c-bad4-343d92061871",
                                 name="default:busybox-test",
                                 type="OS::Kubernetes::Pod")))