@@ -40,29 +40,31 @@ def target_platform
4040 else
4141 '5.5.3'
4242 end
43- # test the agent isn't already installed and that the version task works
43+
44+ # Test the agent isn't already installed and that the version task works
4445 results = run_task ( 'puppet_agent::version' , 'target' , { } )
4546 results . each do |res |
4647 expect ( res ) . to include ( 'status' => 'success' )
4748 expect ( res [ 'result' ] [ 'version' ] ) . to eq ( nil )
4849 end
4950
50- # Try to install an older version
51+ # Try to install an older puppet5 version
5152 results = run_task ( 'puppet_agent::install' , 'target' , { 'collection' => 'puppet5' ,
5253 'version' => puppet_5_version ,
5354 'stop_service' => true } )
5455 results . each do |res |
5556 expect ( res ) . to include ( 'status' => 'success' )
5657 end
5758
58- # It installed a version older than latest
59+ # It installed a version older than latest puppet5
5960 results = run_task ( 'puppet_agent::version' , 'target' , { } )
6061 results . each do |res |
6162 expect ( res ) . to include ( 'status' => 'success' )
6263 expect ( res [ 'result' ] [ 'version' ] ) . to eq ( puppet_5_version )
6364 expect ( res [ 'result' ] [ 'source' ] ) . to be
6465 end
6566
67+ # Check that puppet agent service has been stopped due to 'stop_service' parameter set to true
6668 service = if target_platform =~ /win/
6769 run_command ( 'c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet' , 'target' )
6870 else
@@ -71,21 +73,23 @@ def target_platform
7173 output = service [ 0 ] [ 'result' ] [ 'stdout' ]
7274 expect ( output ) . to include ( "ensure => 'stopped'" )
7375
74- # Run with no argument upgrades
76+ # Try to upgrade with no specific version given in parameter
77+ # Expect nothing to happen and receive a message regarding this
7578 results = run_task ( 'puppet_agent::install' , 'target' , { 'collection' => 'puppet5' } )
7679 results . each do |res |
7780 expect ( res ) . to include ( 'status' => 'success' )
81+ expect ( res [ 'result' ] [ '_output' ] ) . to match ( %r{Version parameter not defined and agent detected. Nothing to do.} )
7882 end
7983
80- # Verify that it did nothing
84+ # Verify that the version didn't change
8185 results = run_task ( 'puppet_agent::version' , 'target' , { } )
8286 results . each do |res |
8387 expect ( res ) . to include ( 'status' => 'success' )
8488 expect ( res [ 'result' ] [ 'version' ] ) . to eq ( puppet_5_version )
8589 expect ( res [ 'result' ] [ 'source' ] ) . to be
8690 end
8791
88- # Run with latest upgrades
92+ # Upgrade to latest puppet5 version
8993 results = run_task ( 'puppet_agent::install' , 'target' , { 'collection' => 'puppet5' , 'version' => 'latest' } )
9094 results . each do |res |
9195 expect ( res ) . to include ( 'status' => 'success' )
@@ -100,19 +104,44 @@ def target_platform
100104 expect ( res [ 'result' ] [ 'source' ] ) . to be
101105 end
102106
103- # Upgrade from puppet5 to puppet6
107+ # Puppet Agent can't be upgraded on Windows nodes while 'puppet agent' service or 'pxp-agent' service are running
108+ if target_platform =~ /win/
109+ # Try to upgrade from puppet5 to puppet6 but fail due to puppet agent service already running
110+ results = run_task ( 'puppet_agent::install' , 'target' , { 'collection' => 'puppet6' , 'version' => 'latest' } )
111+ results . each do |res |
112+ expect ( res ) . to include ( 'status' => 'failure' )
113+ expect ( res [ 'result' ] [ '_error' ] [ 'msg' ] ) . to match ( %r{Puppet Agent upgrade cannot be done while Puppet services are still running.} )
114+ end
115+
116+ # Manually stop the puppet agent service
117+ service = run_command ( 'c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet ensure=stopped' , 'target' )
118+ output = service [ 0 ] [ 'result' ] [ 'stdout' ]
119+ expect ( output ) . to include ( "ensure => 'stopped'" )
120+ end
121+
122+ # Succesfully upgrade from puppet5 to puppet6
104123 results = run_task ( 'puppet_agent::install' , 'target' , { 'collection' => 'puppet6' , 'version' => 'latest' } )
105124 results . each do |res |
106125 expect ( res ) . to include ( 'status' => 'success' )
107126 end
108127
109128 # Verify that it upgraded
129+ installed_version = nil
110130 results = run_task ( 'puppet_agent::version' , 'target' , { } )
111131 results . each do |res |
112132 expect ( res ) . to include ( 'status' => 'success' )
113- expect ( res [ 'result' ] [ 'version' ] ) . not_to match ( %r{^5\. \d +\. \d +} )
114- expect ( res [ 'result' ] [ 'version' ] ) . to match ( %r{^6\. \d +\. \d +} )
133+ installed_version = res [ 'result' ] [ 'version' ]
134+ expect ( installed_version ) . not_to match ( %r{^5\. \d +\. \d +} )
135+ expect ( installed_version ) . to match ( %r{^6\. \d +\. \d +} )
115136 expect ( res [ 'result' ] [ 'source' ] ) . to be
116137 end
138+
139+ # Try installing the same version again
140+ # Expect nothing to happen and receive a message regarding this
141+ results = run_task ( 'puppet_agent::install' , 'target' , { 'collection' => 'puppet6' , 'version' => installed_version } )
142+ results . each do |res |
143+ expect ( res ) . to include ( 'status' => 'success' )
144+ expect ( res [ 'result' ] [ '_output' ] ) . to match ( %r{Puppet Agent #{ installed_version } detected. Nothing to do.} )
145+ end
117146 end
118147end
0 commit comments