@@ -490,7 +490,9 @@ def test_backup_restore(self):
490490
491491class TestBackupSet (TestBackup ):
492492
493- backup = volume_fakes .FakeBackup .create_one_backup ()
493+ backup = volume_fakes .FakeBackup .create_one_backup (
494+ attrs = {'metadata' : {'wow' : 'cool' }},
495+ )
494496
495497 def setUp (self ):
496498 super (TestBackupSet , self ).setUp ()
@@ -627,6 +629,159 @@ def test_backup_set_state_failed(self):
627629 self .backups_mock .reset_state .assert_called_with (
628630 self .backup .id , 'error' )
629631
632+ def test_backup_set_no_property (self ):
633+ self .app .client_manager .volume .api_version = \
634+ api_versions .APIVersion ('3.43' )
635+
636+ arglist = [
637+ '--no-property' ,
638+ self .backup .id ,
639+ ]
640+ verifylist = [
641+ ('no_property' , True ),
642+ ('backup' , self .backup .id ),
643+ ]
644+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
645+
646+ result = self .cmd .take_action (parsed_args )
647+
648+ # Set expected values
649+ kwargs = {
650+ 'metadata' : {},
651+ }
652+ self .backups_mock .update .assert_called_once_with (
653+ self .backup .id ,
654+ ** kwargs
655+ )
656+ self .assertIsNone (result )
657+
658+ def test_backup_set_no_property_pre_v343 (self ):
659+ self .app .client_manager .volume .api_version = \
660+ api_versions .APIVersion ('3.42' )
661+
662+ arglist = [
663+ '--no-property' ,
664+ self .backup .id ,
665+ ]
666+ verifylist = [
667+ ('no_property' , True ),
668+ ('backup' , self .backup .id ),
669+ ]
670+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
671+
672+ exc = self .assertRaises (
673+ exceptions .CommandError ,
674+ self .cmd .take_action ,
675+ parsed_args )
676+ self .assertIn ("--os-volume-api-version 3.43 or greater" , str (exc ))
677+
678+ def test_backup_set_property (self ):
679+ self .app .client_manager .volume .api_version = \
680+ api_versions .APIVersion ('3.43' )
681+
682+ arglist = [
683+ '--property' , 'foo=bar' ,
684+ self .backup .id ,
685+ ]
686+ verifylist = [
687+ ('properties' , {'foo' : 'bar' }),
688+ ('backup' , self .backup .id ),
689+ ]
690+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
691+
692+ result = self .cmd .take_action (parsed_args )
693+
694+ # Set expected values
695+ kwargs = {
696+ 'metadata' : {'wow' : 'cool' , 'foo' : 'bar' },
697+ }
698+ self .backups_mock .update .assert_called_once_with (
699+ self .backup .id ,
700+ ** kwargs
701+ )
702+ self .assertIsNone (result )
703+
704+ def test_backup_set_property_pre_v343 (self ):
705+ self .app .client_manager .volume .api_version = \
706+ api_versions .APIVersion ('3.42' )
707+
708+ arglist = [
709+ '--property' , 'foo=bar' ,
710+ self .backup .id ,
711+ ]
712+ verifylist = [
713+ ('properties' , {'foo' : 'bar' }),
714+ ('backup' , self .backup .id ),
715+ ]
716+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
717+
718+ exc = self .assertRaises (
719+ exceptions .CommandError ,
720+ self .cmd .take_action ,
721+ parsed_args )
722+ self .assertIn ("--os-volume-api-version 3.43 or greater" , str (exc ))
723+
724+
725+ class TestBackupUnset (TestBackup ):
726+
727+ backup = volume_fakes .FakeBackup .create_one_backup (
728+ attrs = {'metadata' : {'foo' : 'bar' }},
729+ )
730+
731+ def setUp (self ):
732+ super ().setUp ()
733+
734+ self .backups_mock .get .return_value = self .backup
735+
736+ # Get the command object to test
737+ self .cmd = volume_backup .UnsetVolumeBackup (self .app , None )
738+
739+ def test_backup_unset_property (self ):
740+ self .app .client_manager .volume .api_version = \
741+ api_versions .APIVersion ('3.43' )
742+
743+ arglist = [
744+ '--property' , 'foo' ,
745+ self .backup .id ,
746+ ]
747+ verifylist = [
748+ ('properties' , ['foo' ]),
749+ ('backup' , self .backup .id ),
750+ ]
751+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
752+
753+ result = self .cmd .take_action (parsed_args )
754+
755+ # Set expected values
756+ kwargs = {
757+ 'metadata' : {},
758+ }
759+ self .backups_mock .update .assert_called_once_with (
760+ self .backup .id ,
761+ ** kwargs
762+ )
763+ self .assertIsNone (result )
764+
765+ def test_backup_unset_property_pre_v343 (self ):
766+ self .app .client_manager .volume .api_version = \
767+ api_versions .APIVersion ('3.42' )
768+
769+ arglist = [
770+ '--property' , 'foo' ,
771+ self .backup .id ,
772+ ]
773+ verifylist = [
774+ ('properties' , ['foo' ]),
775+ ('backup' , self .backup .id ),
776+ ]
777+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
778+
779+ exc = self .assertRaises (
780+ exceptions .CommandError ,
781+ self .cmd .take_action ,
782+ parsed_args )
783+ self .assertIn ("--os-volume-api-version 3.43 or greater" , str (exc ))
784+
630785
631786class TestBackupShow (TestBackup ):
632787
0 commit comments