当前位置: 首页>>代码示例>>Python>>正文


Python Volume.volume_state方法代码示例

本文整理汇总了Python中boto.ec2.volume.Volume.volume_state方法的典型用法代码示例。如果您正苦于以下问题:Python Volume.volume_state方法的具体用法?Python Volume.volume_state怎么用?Python Volume.volume_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.ec2.volume.Volume的用法示例。


在下文中一共展示了Volume.volume_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VolumeTests

# 需要导入模块: from boto.ec2.volume import Volume [as 别名]
# 或者: from boto.ec2.volume.Volume import volume_state [as 别名]

#.........这里部分代码省略.........
            self.check_that_attribute_has_been_set(arguments[0], arguments[1], arguments[2])

    def test_endElement_with_name_status_and_empty_string_value_doesnt_set_status(self):
        volume = Volume()
        volume.endElement("status", "", None)
        self.assertNotEqual(volume.status, "")

    def test_update_with_result_set_greater_than_0_updates_dict(self):
        self.volume_two.connection.get_all_volumes.return_value = [self.volume_one]
        self.volume_two.update()

        assert all([self.volume_two.create_time == 5,
                    self.volume_two.status == "one_status",
                    self.volume_two.size == "one_size",
                    self.volume_two.snapshot_id == 1,
                    self.volume_two.attach_data == self.attach_data,
                    self.volume_two.zone == "one_zone"])

    def test_update_with_validate_true_raises_value_error(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_volumes.return_value = []
        with self.assertRaisesRegexp(ValueError, "^1 is not a valid Volume ID$"):
            self.volume_one.update(True)

    def test_update_returns_status(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_volumes.return_value = [self.volume_two]
        retval = self.volume_one.update()
        self.assertEqual(retval, "two_status")

    def test_delete_calls_delete_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.delete()
        self.volume_one.connection.delete_volume.assert_called_with(1)

    def test_attach_calls_attach_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.attach("instance_id", "/dev/null")
        self.volume_one.connection.attach_volume.assert_called_with(1, "instance_id", "/dev/null")

    def test_detach_calls_detach_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.detach()
        self.volume_one.connection.detach_volume.assert_called_with(
                1, 2, "/dev/null", False)

    def test_detach_with_no_attach_data(self):
        self.volume_two.connection = mock.Mock()
        self.volume_two.detach()
        self.volume_two.connection.detach_volume.assert_called_with(
                1, None, None, False)

    def test_detach_with_force_calls_detach_volume_with_force(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.detach(True)
        self.volume_one.connection.detach_volume.assert_called_with(
                1, 2, "/dev/null", True)


    def test_create_snapshot_calls_connection_create_snapshot(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.create_snapshot()
        self.volume_one.connection.create_snapshot.assert_called_with(
                1, None)

    def test_create_snapshot_with_description(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.create_snapshot("some description")
        self.volume_one.connection.create_snapshot.assert_called_with(
                1, "some description")

    def test_volume_state_returns_status(self):
        retval = self.volume_one.volume_state()
        self.assertEqual(retval, "one_status")

    def test_attachment_state_returns_state(self):
        retval = self.volume_one.attachment_state()
        self.assertEqual(retval, "some status")

    def test_attachment_state_no_attach_data_returns_None(self):
        retval = self.volume_two.attachment_state()
        self.assertEqual(retval, None)

    def test_snapshots_returns_snapshots(self):
        snapshot_one = Snapshot()
        snapshot_one.volume_id = 1
        snapshot_two = Snapshot()
        snapshot_two.volume_id = 2

        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_snapshots.return_value = [snapshot_one, snapshot_two]
        retval = self.volume_one.snapshots()
        self.assertEqual(retval, [snapshot_one])

    def test_snapshots__with_owner_and_restorable_by(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_snapshots.return_value = []
        self.volume_one.snapshots("owner", "restorable_by")
        self.volume_one.connection.get_all_snapshots.assert_called_with(
                owner="owner", restorable_by="restorable_by")
开发者ID:Timus1712,项目名称:boto,代码行数:104,代码来源:test_volume.py


注:本文中的boto.ec2.volume.Volume.volume_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。