SmartOS state module for managing vms and images#28765
SmartOS state module for managing vms and images#28765cachedout merged 9 commits intosaltstack:developfrom sjorge:state-smartos
Conversation
test datasmartos.config_presentincomplete state (should fail)state_test:
smartos.config_presentlocal:
----------
ID: state_test
Function: smartos.config_present
Result: False
Comment: Missing parameter value for state smartos.config_present
Started:
Duration:
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 0.000 mssetting state_test config option to ''hello world''state_test:
smartos.config_present:
- value: hello worldInitial run local:
----------
ID: state_test
Function: smartos.config_present
Result: True
Comment: added property state_test with value "hello world"
Started: 09:55:24.042407
Duration: 1.828 ms
Changes:
----------
state_test:
hello world
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 1.828 msSequential run local:
----------
ID: state_test
Function: smartos.config_present
Result: True
Comment: property state_test already has value "hello world"
Started: 09:55:53.263671
Duration: 1.268 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 1.268 mssetting state_test config option to ''hello earth''Sequential run (after changing value to ''hello earth'') local:
----------
ID: state_test
Function: smartos.config_present
Result: True
Comment: updated property state_test with value "hello earth"
Started: 09:57:08.431585
Duration: 1.84 ms
Changes:
----------
state_test:
hello earth
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 1.840 msSequential run local:
----------
ID: state_test
Function: smartos.config_present
Result: True
Comment: property state_test already has value "hello earth"
Started: 09:56:31.263671
Duration: 1.242 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 1.242 msContent of /usbkey/config#
# This file was generated by salt
#
...
state_test=hello earth
...smartos.config_absentremoving state_test config optionInitial run state_test:
smartos.config_absentlocal:
----------
ID: state_test
Function: smartos.config_absent
Result: True
Comment: property state_test deleted
Started: 10:03:37.199488
Duration: 2.078 ms
Changes:
----------
state_test:
None
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 2.078 mSequential run local:
----------
ID: state_test
Function: smartos.config_absent
Result: True
Comment: property state_test is absent
Started: 10:04:05.442374
Duration: 1.085 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 1.085 msContent of /usbkey/config#
# This file was generated by salt
#
...smartos.image_presentinstall non-exising image (should fail)xxxe6fa6-6e9b-11e5-8402-1b490459exxx:
smartos.image_presentlocal:
----------
ID: xxxe6fa6-6e9b-11e5-8402-1b490459exxx
Function: smartos.image_present
Result: False
Comment: image xxxe6fa6-6e9b-11e5-8402-1b490459exxx does not exists
Started: 10:24:14.517541
Duration: 14616.011 ms
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 14.616 sinstall image base-64 15.1.3842e6fa6-6e9b-11e5-8402-1b490459e334:
smartos.image_presentlocal:
----------
ID: 842e6fa6-6e9b-11e5-8402-1b490459e334
Function: smartos.image_present
Result: True
Comment: image 842e6fa6-6e9b-11e5-8402-1b490459e334 installed
Started: 10:25:15.014353
Duration: 42248.638 ms
Changes:
----------
842e6fa6-6e9b-11e5-8402-1b490459e334:
base-64@15.3.0 [2015-10-09T15:36:32Z]
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 42.249 ssmartos.image_absentdelete non-exising imagexxxe6fa6-6e9b-11e5-8402-1b490459exxx:
smartos.image_absentlocal:
----------
ID: xxxe6fa6-6e9b-11e5-8402-1b490459exxx
Function: smartos.image_absent
Result: True
Comment: image xxxe6fa6-6e9b-11e5-8402-1b490459exxx is absent
Started: 10:29:44.078355
Duration: 693.984 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 693.984 msdelete image base-64 15.3.0842e6fa6-6e9b-11e5-8402-1b490459e334:
smartos.image_absentlocal:
----------
ID: 842e6fa6-6e9b-11e5-8402-1b490459e334
Function: smartos.image_absent
Result: True
Comment: image 842e6fa6-6e9b-11e5-8402-1b490459e334 deleted
Started: 10:30:13.600480
Duration: 3234.592 ms
Changes:
----------
842e6fa6-6e9b-11e5-8402-1b490459e334:
None
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 3.235 ssmartos.image_vacuumbase-64 15.1.3 does not get vacuumed because in use by vm or installed via image_present842e6fa6-6e9b-11e5-8402-1b490459e334:
smartos.image_present
vacuum_images:
smartos.image_vacuumlocal:
----------
ID: 842e6fa6-6e9b-11e5-8402-1b490459e334
Function: smartos.image_present
Result: True
Comment: image 842e6fa6-6e9b-11e5-8402-1b490459e334 is present
Started: 10:33:10.595022
Duration: 679.373 ms
Changes:
----------
ID: vacuum_images
Function: smartos.image_vacuum
Result: True
Comment: no images deleted
Started: 10:33:11.275308
Duration: 1205.413 ms
Changes:
Summary for local
------------
Succeeded: 2
Failed: 0
------------
Total states run: 2
Total run time: 1.885 sbase-64 15.1.3 gets vacuumed because not in use or installed via image_presentvacuum_images:
smartos.image_vacuumlocal:
----------
ID: vacuum_images
Function: smartos.image_vacuum
Result: True
Comment: images deleted
Started: 10:34:07.889027
Duration: 2839.453 ms
Changes:
----------
842e6fa6-6e9b-11e5-8402-1b490459e334:
None
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 2.839 ssmartos.vm_runningno existing vmnina.acheron.be:
smartos.vm_runninglocal:
----------
ID: nina.acheron.be
Function: smartos.vm_running
Result: False
Comment: failed to start nina.acheron.be
Started: 10:46:12.631570
Duration: 1045.48 ms
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 1.045 sstopped vmtest.acheron.be:
smartos.vm_runninglocal:
----------
ID: test.acheron.be
Function: smartos.vm_running
Result: True
Comment: vm test.acheron.be started
Started: 10:47:18.634534
Duration: 4046.712 ms
Changes:
----------
test.acheron.be:
running
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 4.047 srunning vmtest.acheron.be:
smartos.vm_runninglocal:
----------
ID: test.acheron.be
Function: smartos.vm_running
Result: True
Comment: vm test.acheron.be already running
Started: 10:47:46.265922
Duration: 489.107 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 489.107 mssmartos.vm_stoppedno existing vmnina.acheron.be:
smartos.vm_stoppedlocal:
----------
ID: nina.acheron.be
Function: smartos.vm_stopped
Result: False
Comment: failed to stop nina.acheron.be
Started: 10:49:35.211013
Duration: 1017.519 ms
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 1.018 sstopped vmtest.acheron.be:
smartos.vm_stoppedlocal:
----------
ID: test.acheron.be
Function: smartos.vm_stopped
Result: True
Comment: vm test.acheron.be already stopped
Started: 10:49:14.527360
Duration: 502.72 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 502.720 msrunning vmtest.acheron.be:
smartos.vm_stoppedlocal:
----------
ID: test.acheron.be
Function: smartos.vm_stopped
Result: True
Comment: vm test.acheron.be stopped
Started: 10:48:16.675644
Duration: 9857.206 ms
Changes:
----------
test.acheron.be:
stopped
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 9.857 ssmartos.vm_absentdeleteing existing vmtest.acheron.be:
smartos.vm_absentlocal:
----------
ID: test.acheron.be
Function: smartos.vm_absent
Result: True
Comment: vm test.acheron.be deleted
Started: 10:53:54.674219
Duration: 2760.56 ms
Changes:
----------
test.acheron.be:
None
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 2.761 sdeleting non-existing vmtest.acheron.be:
smartos.vm_absentlocal:
----------
ID: test.acheron.be
Function: smartos.vm_absent
Result: True
Comment: vm test.acheron.be is absent
Started: 10:54:07.486133
Duration: 491.909 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 491.909 mssmartos.vm_presentcreate vm with incomplete config (failure expected)test.acheron.be:
smartos.vm_present:
- vmconfig:
- image_uuid: e69a0918-055d-11e5-8912-e3ceb6df4cf8
- alias: test
- quota: 1
- max_physical_memory: 512local:
----------
ID: test.acheron.be
Function: smartos.vm_present
Result: False
Comment: {u'bad_brand': u'undefined'}
Started: 10:55:27.264857
Duration: 1613.725 ms
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 1.614 sComment is taking from vmadm.create failure reason create vm with image that is not installed (failure expected)test.acheron.be:
smartos.vm_present:
- vmconfig:
- image_uuid: 842e6fa6-6e9b-11e5-8402-1b490459e334
- brand: joyent
- alias: test
- quota: 1
- max_physical_memory: 512local:
----------
ID: test.acheron.be
Function: smartos.vm_present
Result: False
Comment: image 842e6fa6-6e9b-11e5-8402-1b490459e334 not installed
Started: 10:57:52.092539
Duration: 1172.281 ms
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 1.172 sWe can make vm_present install the image if it exists by adding create vmtest.acheron.be:
smartos.vm_present:
- config:
- auto_import: true
- vmconfig:
- image_uuid: e69a0918-055d-11e5-8912-e3ceb6df4cf8
- brand: joyent
- alias: test
- quota: 1
- max_physical_memory: 512local:
----------
ID: test.acheron.be
Function: smartos.vm_present
Result: True
Comment: vm test.acheron.be created
Started: 11:00:15.114554
Duration: 86048.114 ms
Changes:
----------
test.acheron.be:
----------
alias:
test
brand:
joyent
hostname:
test.acheron.be
image_uuid:
842e6fa6-6e9b-11e5-8402-1b490459e334
max_physical_memory:
512
quota:
1
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 86.048 supdate vm (add 2 nics)test.acheron.be:
smartos.vm_present:
- config:
- auto_import: true
- vmconfig:
- image_uuid: 842e6fa6-6e9b-11e5-8402-1b490459e334
- brand: joyent
- alias: test
- quota: 1
- max_physical_memory: 512
- nics:
-
- mac: "82:1b:8e:49:e9:12"
- nic_tag: trunk
- mtu: 1500
- ips: [ "dhcp" ]
- vlan_id: 10
-
- mac: "82:1b:8e:49:e9:13"
- nic_tag: trunk
- mtu: 1500
- ips: [ "dhcp" ]
- vlan_id: 30local:
----------
ID: test.acheron.be
Function: smartos.vm_present
Result: True
Comment: vm test.acheron.be updated
Started: 11:03:18.947881
Duration: 5971.735 ms
Changes:
----------
test.acheron.be:
----------
add_nics:
|_
----------
ips:
- dhcp
mac:
82:1b:8e:49:e9:12
mtu:
1500
nic_tag:
trunk
vlan_id:
10
|_
----------
ips:
- dhcp
mac:
82:1b:8e:49:e9:13
mtu:
1500
nic_tag:
trunk
vlan_id:
30
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 5.972 supdate vm (actually, we only need 1 nic but more diskspace)test.acheron.be:
smartos.vm_present:
- config:
- auto_import: true
- vmconfig:
- image_uuid: 842e6fa6-6e9b-11e5-8402-1b490459e334
- brand: joyent
- alias: test
- quota: 5
- max_physical_memory: 512
- nics:
-
- mac: "82:1b:8e:49:e9:12"
- nic_tag: trunk
- mtu: 1500
- ips: [ "dhcp" ]
- vlan_id: 10local:
----------
ID: test.acheron.be
Function: smartos.vm_present
Result: True
Comment: vm test.acheron.be updated
Started: 11:04:39.366550
Duration: 4964.617 ms
Changes:
----------
test.acheron.be:
----------
quota:
5
remove_nics:
- 82:1b:8e:49:e9:13
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 4.965 sreprovision vm (failure)Oh boy! The jr. sysadmin used the latest and greatest base-64 image! Not the lts one. Let's fix that! test.acheron.be:
smartos.vm_present:
- config:
- auto_import: true
- vmconfig:
- image_uuid: c02a2044-c1bd-11e4-bd8c-dfc1db8b0182
- brand: joyent
- alias: test
- quota: 5
- max_physical_memory: 512
- nics:
-
- mac: "82:1b:8e:49:e9:12"
- nic_tag: trunk
- mtu: 1500
- ips: [ "dhcp" ]
- vlan_id: 10local:
----------
ID: test.acheron.be
Function: smartos.vm_present
Result: True
Comment: vm test.acheron.be is up to date
Started: 11:05:56.265247
Duration: 1657.178 ms
Changes:
Summary for local
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 1.657 s:?: what's this? Actually this is correct, reprovision destroys the vm and creates it again! reprovision vm (with config
|
salt/states/smartos.py
Outdated
There was a problem hiding this comment.
salt.utils.fopen instead, please.
|
Hi @sjorge. This looks great. There are a few minor concerns that I have that I left as comments in-line. Could you please have a look and let me know what you think? |
|
Thanks @cachedout, all comments make sense. Fixing them now. I wasn't aware of salt.utils.fopen, is there a doc somewhere describing some of the commonly use utils? I also found the dict compare one by actually grepping the code for examples (my custom code was not python 2.6 compatible). And it indeed looks like those parentheses were not necessary. local:
----------
ID: 7bcfc9c8-6e9a-11e5-8d57-73e262d7338e
Function: smartos.image_absent
Result: True
Comment: image 7bcfc9c8-6e9a-11e5-8d57-73e262d7338e deleted
Started: 16:06:59.321483
Duration: 2491.202 ms
Changes:
----------
7bcfc9c8-6e9a-11e5-8d57-73e262d7338e:
None
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 2.491 sFollow up commits incoming. |
|
@sjorge I've meant to add the utils docs to the Contributor Guidelines but I haven't had a chance. Thanks for the reminder. I'll try to get that in today. Great idea! |
|
That would be awesome :) One more commit incoming, adding a bit more context where available for the log messages |
|
Sounds great. Just let me know when this is ready to go. Thanks! |
|
All done, [WARNING ] smartos.vm_present::test.acheron.be::reprovision - image_uuid in state does not match current, reprovision not allowed |
|
Great! After the tests finish running, I will get this in. Much appreciated, @sjorge. This will be a valuable addition to Salt. |
SmartOS state module for managing vms and images
Although this PR is separate from #28734, all testing was done with the changes from #28734 in place.
This PR implements the ideas discussed in #27658.
Included in the state module is:
For more information the docs for each of these states.
There is a esky packages available for testing here: http://sjorge.sinners.be/illumos/joyent/salt-2015.8.0-661-ga3abab1-esky-smartos.tar.gz