Beispiel #1
0
    def test_check_cluster_volume_mounts_not_ready(
            self, mock_describe_cluster_instances):
        """Assert checking the volume mounts when they are not ready."""
        device_mappings = [
            util_helper.generate_dummy_block_device_mapping(
                device_name=self.ami_mountpoints[0][1], status="attaching"),
            util_helper.generate_dummy_block_device_mapping(
                device_name=self.ami_mountpoints[1][1], status="suspicious"),
        ]
        described_instances = {
            self.ec2_instance_id:
            util_helper.generate_dummy_describe_instance(
                instance_id=self.ec2_instance_id,
                device_mappings=device_mappings)
        }
        mock_describe_cluster_instances.return_value = described_instances

        with self.assertLogs("api.clouds.aws.tasks.inspection",
                             level="INFO") as logging_watcher:
            volumes_mounted = tasks.inspection._check_cluster_volume_mounts(
                self.ec2_instance_id, self.ami_mountpoints)

        self.assertFalse(volumes_mounted)
        self.assertEqual(len(logging_watcher.output), 3)
        self.assertIn("INFO", logging_watcher.output[0])
        self.assertIn("is still attaching", logging_watcher.output[0])
        self.assertIn("ERROR", logging_watcher.output[1])
        self.assertIn("has unexpected status", logging_watcher.output[1])
        self.assertIn("WARNING", logging_watcher.output[2])
        self.assertIn("not found in", logging_watcher.output[2])
Beispiel #2
0
 def test_generate_dummy_block_device_mapping_default(self):
     """Assert generated block device mapping has values where expected."""
     device_mapping = helper.generate_dummy_block_device_mapping()
     self.assertIsNotNone(device_mapping["DeviceName"])
     self.assertTrue(device_mapping["DeviceName"].startswith("/dev/"))
     self.assertIsNotNone(device_mapping["Ebs"])
     self.assertEqual(device_mapping["Ebs"]["AttachTime"],
                      "2020-01-02T03:04:05+00:00")
     self.assertTrue(device_mapping["Ebs"]["DeleteOnTermination"])
     self.assertEqual(device_mapping["Ebs"]["Status"], "attached")
     self.assertIsNotNone(device_mapping["Ebs"]["VolumeId"])
     self.assertTrue(device_mapping["Ebs"]["VolumeId"].startswith("vol-"))
Beispiel #3
0
    def test_check_cluster_volume_mounts_success(
            self, mock_describe_cluster_instances):
        """Assert successfully checking the volume mounts are ready."""
        device_mappings = [
            util_helper.generate_dummy_block_device_mapping(
                device_name=self.ami_mountpoints[0][1]),
            util_helper.generate_dummy_block_device_mapping(
                device_name=self.ami_mountpoints[1][1]),
            util_helper.generate_dummy_block_device_mapping(
                device_name=self.ami_mountpoints[2][1]),
        ]
        described_instances = {
            self.ec2_instance_id:
            util_helper.generate_dummy_describe_instance(
                instance_id=self.ec2_instance_id,
                device_mappings=device_mappings)
        }
        mock_describe_cluster_instances.return_value = described_instances

        volumes_mounted = tasks.inspection._check_cluster_volume_mounts(
            self.ec2_instance_id, self.ami_mountpoints)
        self.assertTrue(volumes_mounted)
Beispiel #4
0
 def test_generate_dummy_block_device_mapping_with_values(self):
     """Assert generated block device mapping contains given values."""
     device_name = "/dev/potato"
     device_type = "gem"
     attach_time = "2020-10-08T16:16:16+00:00"
     delete_on_termination = False
     status = "delicious"
     volume_id = "vol-taters"
     device_mapping = helper.generate_dummy_block_device_mapping(
         device_name=device_name,
         device_type=device_type,
         attach_time=attach_time,
         delete_on_termination=delete_on_termination,
         status=status,
         volume_id=volume_id,
     )
     self.assertEqual(device_mapping["DeviceName"], device_name)
     self.assertIn(device_type, device_mapping)
     self.assertEqual(device_mapping[device_type]["AttachTime"],
                      attach_time)
     self.assertFalse(device_mapping[device_type]["DeleteOnTermination"])
     self.assertEqual(device_mapping[device_type]["Status"], status)
     self.assertEqual(device_mapping[device_type]["VolumeId"], volume_id)
Beispiel #5
0
 def test_generate_dummy_describe_instance_with_values(self):
     """Assert generated instance contains given values."""
     image_id = helper.generate_dummy_image_id()
     instance_id = helper.generate_dummy_instance_id()
     subnet_id = helper.generate_dummy_subnet_id()
     state = aws.InstanceState.shutting_down
     instance_type = helper.get_random_instance_type()
     device_mapping = helper.generate_dummy_block_device_mapping()
     instance = helper.generate_dummy_describe_instance(
         instance_id=instance_id,
         image_id=image_id,
         subnet_id=subnet_id,
         state=state,
         instance_type=instance_type,
         device_mappings=[device_mapping],
     )
     self.assertEqual(instance["ImageId"], image_id)
     self.assertEqual(instance["InstanceId"], instance_id)
     self.assertEqual(instance["InstanceType"], instance_type)
     self.assertEqual(instance["SubnetId"], subnet_id)
     self.assertEqual(instance["State"]["Code"], state.value)
     self.assertEqual(instance["State"]["Name"], state.name)
     self.assertEqual(instance["State"]["Name"], state.name)
     self.assertEqual(instance["BlockDeviceMappings"], [device_mapping])