1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
|
"""
SoftLayer.tests.CLI.modules.server_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a series of integration tests designed to test the complete
command line interface.
:license: MIT, see LICENSE for more details.
"""
import json
import sys
import tempfile
from unittest import mock as mock
from SoftLayer.CLI import exceptions
from SoftLayer.fixtures import SoftLayer_Product_Order
from SoftLayer import SoftLayerError
from SoftLayer import testing
from SoftLayer import utils
class HardwareCLITests(testing.TestCase):
def test_server_cancel_reasons(self):
result = self.run_command(['server', 'cancel-reasons'])
output = json.loads(result.output)
self.assert_no_fail(result)
self.assertEqual(len(output), 10)
def test_server_credentials(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
mock.return_value = {
"accountId": 11111,
"domain": "chechu.com",
"fullyQualifiedDomainName": "host3.vmware.chechu.com",
"hardwareStatusId": 5,
"hostname": "host3.vmware",
"id": 12345,
"softwareComponents": [{"passwords": [
{
"password": "abc123",
"username": "root"
}],
'softwareLicense': {
'softwareDescription':
{
'referenceCode': 'CENTOS_7_64',
'version': '7.8 - 64',
'name': 'Centos'
}}}]
}
result = self.run_command(['hardware', 'credentials', '12345'])
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), [
{'Password': 'abc123',
'Software': 'Centos',
'Username': 'root',
'Version': '7.8 - 64'}
])
def test_server_credentials_exception_passwords_not_found(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
mock.return_value = {
"accountId": 11111,
"domain": "chechu.com",
"fullyQualifiedDomainName": "host3.vmware.chechu.com",
"hardwareStatusId": 5,
"hostname": "host3.vmware",
"id": 12345,
"softwareComponents": [{}]
}
result = self.run_command(['hardware', 'credentials', '12345'])
self.assertEqual(
'No passwords found in softwareComponents',
str(result.exception)
)
def test_server_credentials_exception_password_not_found(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
mock.return_value = {
"accountId": 11111,
"domain": "chechu.com",
"fullyQualifiedDomainName": "host3.vmware.chechu.com",
"hardwareStatusId": 5,
"hostname": "host3.vmware",
"id": 12345,
"softwareComponents": [
{
"hardwareId": 22222,
"id": 333333,
"passwords": [{}],
"softwareLicense": {
"softwareDescription": {
"name": None,
"version": None
}
}
}
]
}
result = self.run_command(['hardware', 'credentials', '12345'])
self.assertEqual('None', str(result.exception))
def test_server_details(self):
result = self.run_command(['server', 'detail', '1234', '--passwords', '--price'])
self.assert_no_fail(result)
output = json.loads(result.output)
self.assertEqual(output['notes'], 'These are test notes.')
self.assertEqual(output['prices'][0]['Recurring Price'], 16.08)
self.assertEqual(output['remote users'][0]['password'], 'abc123')
self.assertEqual(output['users'][0]['username'], 'root')
self.assertEqual(output['vlans'][0]['Number'], 1800)
self.assertEqual(output['owner'], 'chechu')
self.assertEqual(output['Bandwidth'][0]['Allotment'], '250')
def test_detail_vs_empty_tag(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getTagReferences')
mock.return_value = [{'tag': {'name': 'example-tag'}}, {}]
result = self.run_command(['server', 'detail', '100'])
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output)['tags'], ['example-tag'])
def test_detail_empty_allotment(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail')
mock.return_value = None
result = self.run_command(['server', 'detail', '100'])
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output)['Bandwidth'][0]['Allotment'], '-')
def test_detail_drives(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getHardDrives')
mock.return_value = [
{
"id": 11111,
"serialNumber": "z1w4sdf",
"hardwareComponentModel": {
"capacity": "1000",
"description": "SATAIII:2000:8300:Constellation",
"id": 111,
"manufacturer": "Seagate",
"name": "Constellation ES",
"hardwareGenericComponentModel": {
"capacity": "1000",
"units": "GB",
"hardwareComponentType": {
"id": 1,
"keyName": "HARD_DRIVE",
"type": "Hard Drive",
"typeParentId": 5
}
}
}
}
]
result = self.run_command(['server', 'detail', '100'])
self.assert_no_fail(result)
output = json.loads(result.output)
self.assertEqual(output['drives'][0]['Capacity'], '1000 GB')
self.assertEqual(output['drives'][0]['Name'], 'Seagate Constellation ES')
self.assertEqual(output['drives'][0]['Serial #'], 'z1w4sdf')
def test_list_servers(self):
result = self.run_command(['server', 'list', '--tag=openstack'])
expected = [
{
'datacenter': 'TEST00',
'primary_ip': '172.16.1.100',
'hostname': 'hardware-test1',
'id': 1000,
'backend_ip': '10.1.0.2',
'action': 'TXN_NAME',
},
{
'datacenter': 'TEST00',
'primary_ip': '172.16.4.94',
'hostname': 'hardware-test2',
'id': 1001,
'backend_ip': '10.1.0.3',
'action': None,
},
{
'datacenter': 'TEST00',
'primary_ip': '172.16.4.95',
'hostname': 'hardware-bad-memory',
'id': 1002,
'backend_ip': '10.1.0.4',
'action': None,
},
{
'action': None,
'backend_ip': None,
'datacenter': None,
'hostname': None,
'id': 1003,
'primary_ip': None,
},
]
self.assert_no_fail(result)
self.assertEqual(expected, json.loads(result.output))
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
@mock.patch('SoftLayer.HardwareManager.reload')
def test_server_reload(self, reload_mock, ngb_mock):
ngb_mock.return_value = False
# Check the positive case
result = self.run_command(['--really', 'server', 'reload', '12345', '--key=4567'])
self.assert_no_fail(result)
reload_mock.assert_called_with(12345, None, [4567], False)
# LVM switch
result = self.run_command(['--really', 'server', 'reload', '12345', '--lvm'])
self.assert_no_fail(result)
reload_mock.assert_called_with(12345, None, [], True)
# Now check to make sure we properly call CLIAbort in the negative case
result = self.run_command(['server', 'reload', '12345'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
@mock.patch('SoftLayer.HardwareManager.cancel_hardware')
def test_cancel_server(self, cancel_mock, ngb_mock):
ngb_mock.return_value = False
# Check the positive case
result = self.run_command(['--really', 'server', 'cancel', '12345', '--reason=Test', '--comment=Test'])
self.assert_no_fail(result)
cancel_mock.assert_called_with(12345, "Test", "Test", False)
# Test
result = self.run_command(['server', 'cancel', '12345', '--reason=Test', '--comment=Test'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_server_power_off(self, confirm_mock):
# Check the positive case
result = self.run_command(['--really', 'server', 'power-off', '12345'])
self.assert_called_with('SoftLayer_Hardware_Server', 'powerOff', identifier=12345)
# Now check to make sure we properly call CLIAbort in the negative case
confirm_mock.return_value = False
result = self.run_command(['server', 'power-off', '12345'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
def test_server_reboot_default(self):
result = self.run_command(['--really', 'server', 'reboot', '12345'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Hardware_Server', 'rebootDefault', identifier=12345)
def test_server_reboot_soft(self):
result = self.run_command(['--really', 'server', 'reboot', '12345', '--soft'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Hardware_Server', 'rebootSoft', identifier=12345)
def test_server_reboot_hard(self):
result = self.run_command(['--really', 'server', 'reboot', '12345', '--hard'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Hardware_Server', 'rebootHard', identifier=12345)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_server_reboot_negative(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['server', 'reboot', '12345'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
def test_server_power_on(self):
result = self.run_command(['--really', 'server', 'power-on', '12345'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Hardware_Server', 'powerOn', identifier=12345)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_harware_power_on_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hardware', 'power-on', '12345'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_harware_power_off_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hardware', 'power-off', '12345'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)
def test_server_power_cycle(self):
result = self.run_command(['--really', 'server', 'power-cycle', '12345'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Hardware_Server', 'powerCycle', identifier=12345)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_server_power_cycle_negative(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['server', 'power-cycle', '12345'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('SoftLayer.HardwareManager.verify_order')
def test_create_server_test_flag(self, verify_mock):
verify_mock.return_value = {
'prices': [
{
'recurringFee': 0.0,
'setupFee': 0.0,
'item': {'description': 'First Item'},
},
{
'recurringFee': 25.0,
'setupFee': 0.0,
'item': {'description': 'Second Item'},
}
]
}
result = self.run_command(['--really', 'server', 'create',
'--size=S1270_8GB_2X1TBSATA_NORAID',
'--hostname=test',
'--domain=example.com',
'--datacenter=TEST00',
'--port-speed=100',
'--os=UBUNTU_12_64',
'--test'],
fmt='raw')
self.assert_no_fail(result)
self.assertIn("First Item", result.output)
self.assertIn("Second Item", result.output)
self.assertIn("Total monthly cost", result.output)
def test_create_options(self):
result = self.run_command(['server', 'create-options'])
self.assert_no_fail(result)
output = json.loads(result.output)
self.assertEqual(output[0][0]['Value'], 'wdc07')
def test_create_options_prices(self):
result = self.run_command(['server', 'create-options', '--prices'])
self.assert_no_fail(result)
output = json.loads(result.output)
self.assertEqual(output[2][0]['Monthly'], str(0.1))
self.assertEqual(output[2][0]['Key'], 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT')
def test_create_options_location(self):
result = self.run_command(['server', 'create-options', '--prices', 'dal13'])
self.assert_no_fail(result)
output = json.loads(result.output)
self.assertEqual(output[2][0]['Monthly'], str(0.1))
self.assertEqual(output[2][0]['Key'], 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT')
@mock.patch('SoftLayer.HardwareManager.place_order')
def test_create_server(self, order_mock):
order_mock.return_value = {
'orderId': 98765,
'orderDate': '2013-08-02 15:23:47'
}
result = self.run_command(['--really', 'server', 'create',
'--size=S1270_8GB_2X1TBSATA_NORAID',
'--hostname=test',
'--domain=example.com',
'--datacenter=TEST00',
'--port-speed=100',
'--os=OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
'--no-public',
'--key=10',
])
self.assert_no_fail(result)
self.assertIn('Warning: Closed soon: TEST00.pod2', result.output)
self.assertIn('"id": 98765', result.output)
result = self.run_command(['--really', 'server', 'create',
'--size=S1270_8GB_2X1TBSATA_NORAID',
'--hostname=test',
'--domain=example.com',
'--datacenter=mex01',
'--os=OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
])
self.assert_no_fail(result)
self.assertNotIn('Warning: Closed soon: mex01', result.output)
@mock.patch('SoftLayer.CLI.template.export_to_template')
def test_create_server_with_export(self, export_mock):
result = self.run_command(['--really', 'server', 'create',
'--size=S1270_8GB_2X1TBSATA_NORAID',
'--hostname=test',
'--domain=example.com',
'--datacenter=TEST00',
'--port-speed=100',
'--os=UBUNTU_12_64',
'--no-public',
'--export=/path/to/test_file.txt'],
fmt='raw')
self.assert_no_fail(result)
self.assertIn("Successfully exported options to a template file.", result.output)
export_mock.assert_called_once()
@mock.patch('SoftLayer.HardwareManager.place_order')
def test_create_server_with_router(self, order_mock):
order_mock.return_value = {
'orderId': 98765,
'orderDate': '2013-08-02 15:23:47'
}
result = self.run_command(['--really', 'server', 'create',
'--size=S1270_8GB_2X1TBSATA_NORAID',
'--hostname=test',
'--domain=example.com',
'--datacenter=TEST00',
'--port-speed=100',
'--os=OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
'--router-private=123',
'--router-public=1234'
])
self.assert_no_fail(result)
def test_edit_server_userdata_and_file(self):
# Test both userdata and userfile at once
with tempfile.NamedTemporaryFile() as userfile:
result = self.run_command(['server', 'edit', '1000',
'--hostname=hardware-test1',
'--domain=test.sftlyr.ws',
'--userdata=My data',
'--userfile=%s' % userfile.name])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.ArgumentError)
def test_edit_server_userdata(self):
result = self.run_command(['server', 'edit', '1000',
'--hostname=hardware-test1',
'--domain=test.sftlyr.ws',
'--userdata=My data'])
self.assert_no_fail(result)
self.assertEqual(result.output, "")
self.assert_called_with('SoftLayer_Hardware_Server', 'editObject',
args=({'domain': 'test.sftlyr.ws', 'hostname': 'hardware-test1'},),
identifier=1000)
@mock.patch('SoftLayer.HardwareManager.edit')
def test_edit_server_failed(self, edit_mock):
edit_mock.return_value = False
result = self.run_command(['server', 'edit', '1000',
'--hostname=hardware-test1',
'--domain=test.sftlyr.ws',
'--userdata=My data'])
self.assertEqual(result.exit_code, 2)
self.assertEqual(result.output, "")
edit_mock.assert_called_with(1000, userdata='My data', domain='test.sftlyr.ws', hostname='hardware-test1')
def test_edit_server_userfile(self):
if (sys.platform.startswith("win")):
self.skipTest("Test doesn't work in Windows")
with tempfile.NamedTemporaryFile() as userfile:
userfile.write(b"some data")
userfile.flush()
result = self.run_command(['server', 'edit', '1000', '--userfile=%s' % userfile.name])
self.assert_no_fail(result)
self.assertEqual(result.output, "")
self.assert_called_with('SoftLayer_Hardware_Server', 'setUserMetadata',
args=(['some data'],), identifier=1000)
def test_edit(self):
result = self.run_command(['server', 'edit',
'--domain=example.com',
'--hostname=host',
'--userdata="testdata"',
'--tag=dev',
'--tag=green',
'--public-speed=10',
'--redundant',
'--private-speed=100',
'--degraded',
'100'])
self.assert_no_fail(result)
self.assertEqual(result.output, '')
self.assert_called_with(
'SoftLayer_Hardware_Server', 'editObject',
args=({'domain': 'example.com', 'hostname': 'host'},),
identifier=100,
)
self.assert_called_with(
'SoftLayer_Hardware_Server', 'setUserMetadata',
args=(['"testdata"'],),
identifier=100,
)
self.assert_called_with(
'SoftLayer_Hardware_Server', 'setPublicNetworkInterfaceSpeed',
args=([10, 'redundant'],),
identifier=100,
)
self.assert_called_with(
'SoftLayer_Hardware_Server', 'setPrivateNetworkInterfaceSpeed',
args=([100, 'degraded'],),
identifier=100,
)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_rescue(self, confirm_mock):
confirm_mock.return_value = True
result = self.run_command(['server', 'rescue', '1000'])
self.assert_no_fail(result)
self.assertEqual(result.output, "")
self.assert_called_with('SoftLayer_Hardware_Server', 'bootToRescueLayer', identifier=1000)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_server_rescue_negative(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['server', 'rescue', '1000'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
def test_ready(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
mock.return_value = {
"provisionDate": "2017-10-17T11:21:53-07:00",
"id": 41957081
}
result = self.run_command(['hw', 'ready', '100'])
self.assert_no_fail(result)
self.assertEqual(result.output, '"READY"\n')
def test_not_ready(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
not_ready = {
'activeTransaction': {
'transactionStatus': {'friendlyName': 'Attach Primary Disk'}
},
'provisionDate': '',
'id': 47392219
}
ready = {
"provisionDate": "2017-10-17T11:21:53-07:00",
"id": 41957081
}
mock.side_effect = [not_ready, ready]
result = self.run_command(['hw', 'ready', '100'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('time.sleep')
def test_going_ready(self, _sleep):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
not_ready = {
'activeTransaction': {
'transactionStatus': {'friendlyName': 'Attach Primary Disk'}
},
'provisionDate': '',
'id': 47392219
}
ready = {
"provisionDate": "2017-10-17T11:21:53-07:00",
"id": 41957081
}
mock.side_effect = [not_ready, ready]
result = self.run_command(['hw', 'ready', '100', '--wait=100'])
self.assert_no_fail(result)
self.assertEqual(result.output, '"READY"\n')
def test_toggle_ipmi_on(self):
mock.return_value = True
result = self.run_command(['server', 'toggle-ipmi', '--enable', '12345'])
self.assert_no_fail(result)
self.assertEqual(result.output, 'true\n')
def test_toggle_ipmi_off(self):
mock.return_value = True
result = self.run_command(['server', 'toggle-ipmi', '--disable', '12345'])
self.assert_no_fail(result)
self.assertEqual(result.output, 'true\n')
def test_bandwidth_hw(self):
if sys.version_info < (3, 6):
self.skipTest("Test requires python 3.6+")
result = self.run_command(['server', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01'])
self.assert_no_fail(result)
date = '2019-05-20 23:00'
# only pyhon 3.7 supports the timezone format slapi uses
if sys.version_info < (3, 7):
date = '2019-05-20T23:00:00-06:00'
split_output = []
for table in utils.decode_stacked(result.output):
split_output.append(table)
self.assertEqual(len(split_output), 2)
output_summary = split_output[0]
output_list = split_output[1]
self.assertEqual(output_summary[0]['Average MBps'], 0.3841)
self.assertEqual(output_summary[1]['Max Date'], date)
self.assertEqual(output_summary[2]['Max GB'], 0.1172)
self.assertEqual(output_summary[3]['Sum GB'], 0.0009)
self.assertEqual(output_list[0]['Date'], date)
self.assertEqual(output_list[0]['Pub In'], 1.3503)
def test_bandwidth_hw_quite(self):
result = self.run_command(['server', 'bandwidth', '100', '--start_date=2019-01-01',
'--end_date=2019-02-01', '-q'])
self.assert_no_fail(result)
date = '2019-05-20 23:00'
# only pyhon 3.7 supports the timezone format slapi uses
if sys.version_info < (3, 7):
date = '2019-05-20T23:00:00-06:00'
output_summary = json.loads(result.output)
self.assertEqual(output_summary[0]['Average MBps'], 0.3841)
self.assertEqual(output_summary[1]['Max Date'], date)
self.assertEqual(output_summary[2]['Max GB'], 0.1172)
self.assertEqual(output_summary[3]['Sum GB'], 0.0009)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_dns_sync_both(self, confirm_mock):
confirm_mock.return_value = True
getReverseDomainRecords = self.set_mock('SoftLayer_Hardware_Server', 'getReverseDomainRecords')
getReverseDomainRecords.return_value = [{
'networkAddress': '172.16.1.100',
'name': '2.240.16.172.in-addr.arpa',
'resourceRecords': [{'data': 'test.softlayer.com.',
'id': 100,
'host': '12'}],
'updateDate': '2013-09-11T14:36:57-07:00',
'serial': 1234665663,
'id': 123456,
}]
getResourceRecords = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
getResourceRecords.return_value = []
createAargs = ({
'type': 'a',
'host': 'hardware-test1',
'domainId': 12345, # from SoftLayer_Account::getDomains
'data': '172.16.1.100',
'ttl': 7200
},)
createPTRargs = ({
'type': 'ptr',
'host': '100',
'domainId': 123456,
'data': 'hardware-test1.test.sftlyr.ws',
'ttl': 7200
},)
result = self.run_command(['hw', 'dns-sync', '1000'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Dns_Domain', 'getResourceRecords')
self.assert_called_with('SoftLayer_Hardware_Server', 'getReverseDomainRecords')
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord', 'createObject', args=createAargs)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord', 'createObject', args=createPTRargs)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_dns_sync_v6(self, confirm_mock):
confirm_mock.return_value = True
getResourceRecords = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
getResourceRecords.return_value = []
server = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
test_server = {
'id': 1000,
'hostname': 'hardware-test1',
'domain': 'sftlyr.ws',
'primaryIpAddress': '172.16.1.100',
'fullyQualifiedDomainName': 'hw-test1.sftlyr.ws',
"primaryNetworkComponent": {}
}
server.return_value = test_server
result = self.run_command(['hw', 'dns-sync', '--aaaa-record', '1000'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
test_server['primaryNetworkComponent'] = {
'primaryVersion6IpAddressRecord': {
'ipAddress': '2607:f0d0:1b01:0023:0000:0000:0000:0004'
}
}
createV6args = ({
'type': 'aaaa',
'host': 'hardware-test1',
'domainId': 12345, # from SoftLayer_Account::getDomains
'data': '2607:f0d0:1b01:0023:0000:0000:0000:0004',
'ttl': 7200
},)
server.return_value = test_server
result = self.run_command(['hw', 'dns-sync', '--aaaa-record', '1000'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord', 'createObject', args=createV6args)
v6Record = {
'id': 1,
'ttl': 7200,
'data': '2607:f0d0:1b01:0023:0000:0000:0000:0004',
'host': 'hardware-test1',
'type': 'aaaa'
}
getResourceRecords = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
getResourceRecords.return_value = [v6Record]
editArgs = (v6Record,)
result = self.run_command(['hw', 'dns-sync', '--aaaa-record', '1000'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord', 'editObject', args=editArgs)
getResourceRecords = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
getResourceRecords.return_value = [v6Record, v6Record]
result = self.run_command(['hw', 'dns-sync', '--aaaa-record', '1000'])
self.assertEqual(result.exit_code, 1)
self.assertIsInstance(result.exception, SoftLayerError)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_dns_sync_edit_a(self, confirm_mock):
confirm_mock.return_value = True
getResourceRecords = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
getResourceRecords.return_value = [
{'id': 1, 'ttl': 7200, 'data': '1.1.1.1',
'host': 'hardware-test1', 'type': 'a'}
]
editArgs = (
{'type': 'a', 'host': 'hardware-test1', 'data': '172.16.1.100',
'id': 1, 'ttl': 7200},
)
result = self.run_command(['hw', 'dns-sync', '-a', '1000'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord', 'editObject', args=editArgs)
getResourceRecords = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
getResourceRecords.return_value = [
{'id': 1, 'ttl': 7200, 'data': '1.1.1.1',
'host': 'hardware-test1', 'type': 'a'},
{'id': 2, 'ttl': 7200, 'data': '1.1.1.1',
'host': 'hardware-test1', 'type': 'a'}
]
result = self.run_command(['hw', 'dns-sync', '-a', '1000'])
self.assertEqual(result.exit_code, 1)
self.assertIsInstance(result.exception, SoftLayerError)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_dns_sync_edit_ptr(self, confirm_mock):
confirm_mock.return_value = True
getReverseDomainRecords = self.set_mock('SoftLayer_Hardware_Server', 'getReverseDomainRecords')
getReverseDomainRecords.return_value = [{
'networkAddress': '172.16.1.100',
'name': '100.1.16.172.in-addr.arpa',
'resourceRecords': [{'data': 'test.softlayer.com.',
'id': 123,
'host': '100'}],
'updateDate': '2013-09-11T14:36:57-07:00',
'serial': 1234665663,
'id': 123456,
}]
editArgs = ({'host': '100', 'data': 'hardware-test1.test.sftlyr.ws', 'id': 123, 'ttl': 7200},)
result = self.run_command(['hw', 'dns-sync', '--ptr', '1000'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord', 'editObject', args=editArgs)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_dns_sync_misc_exception(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'dns-sync', '-a', '1000'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
guest = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
test_guest = {
'id': 1000,
'primaryIpAddress': '',
'hostname': 'hardware-test1',
'domain': 'sftlyr.ws',
'fullyQualifiedDomainName': 'hardware-test1.sftlyr.ws',
"primaryNetworkComponent": {}
}
guest.return_value = test_guest
result = self.run_command(['hw', 'dns-sync', '-a', '1000'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
def test_hardware_storage(self):
result = self.run_command(['hw', 'storage', '100'])
self.assert_no_fail(result)
def test_billing(self):
result = self.run_command(['hw', 'billing', '123456'])
hardware_server_billing = {
'Billing Item Id': 6327,
'Id': '123456',
'Provision Date': None,
'Recurring Fee': 1.54,
'Total': 16.08,
'prices': [
{
'Item': 'test',
'Recurring Price': 1
},
{
'Item': 'test2',
'Recurring Price': 2
},
]
}
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), hardware_server_billing)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_create_hw_no_confirm(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'create', '--hostname=test', '--size=S1270_8GB_2X1TBSATA_NORAID',
'--domain=example.com', '--datacenter=TEST00',
'--network=TEST_NETWORK', '--os=UBUNTU_12_64'])
self.assertEqual(result.exit_code, 2)
self.assertEqual('Aborting dedicated server order.', result.exception.message)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_authorize_hw_no_confirm(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'authorize-storage', '-u', '1234'])
self.assertEqual(result.exit_code, 2)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_authorize_hw_empty(self, confirm_mock):
confirm_mock.return_value = True
storage_result = self.set_mock('SoftLayer_Account', 'getNetworkStorage')
storage_result.return_value = []
result = self.run_command(['hw', 'authorize-storage', '--username-storage=#', '1234'])
self.assertEqual(str(result.exception), "The Storage with username: # was not found, "
"please enter a valid storage username")
def test_authorize_hw(self):
result = self.run_command(['hw', 'authorize-storage', '--username-storage=SL01SEL301234-11', '1234'])
self.assert_no_fail(result)
def test_upgrade_no_options(self, ):
result = self.run_command(['hw', 'upgrade', '100'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.ArgumentError)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade_aborted(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'upgrade', '100', '--memory=1'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
def test_upgrade_test(self):
order_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder')
order_mock.return_value = SoftLayer_Product_Order.hardware_verifyOrder
result = self.run_command(['hw', 'upgrade', '100', '--test', '--memory=32', '--public-bandwidth=500',
'--drive-controller=RAID', '--network=10000 Redundant'])
self.assert_no_fail(result)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade_add_disk(self, confirm_mock):
confirm_mock.return_value = True
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
order_mock.return_value = SoftLayer_Product_Order.hardware_placeOrder
result = self.run_command(['hw', 'upgrade', '100', '--add-disk=1000', '2'])
self.assert_no_fail(result)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade_resize_disk(self, confirm_mock):
confirm_mock.return_value = True
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
order_mock.return_value = SoftLayer_Product_Order.hardware_placeOrder
result = self.run_command(['hw', 'upgrade', '100', '--resize-disk=1000', '1'])
self.assert_no_fail(result)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade_disk_not_price_found(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'upgrade', '100', '--add-disk=1000', '3'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade_disk_already_exist(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'upgrade', '100', '--add-disk=1000', '1'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade_disk_does_not_exist(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hw', 'upgrade', '100', '--resize-disk=1000', '3'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_upgrade(self, confirm_mock):
confirm_mock.return_value = True
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
order_mock.return_value = SoftLayer_Product_Order.hardware_placeOrder
result = self.run_command(['hw', 'upgrade', '100', '--memory=32', '--public-bandwidth=500',
'--drive-controller=RAID', '--network=10000 Redundant'])
self.assert_no_fail(result)
def test_components(self):
result = self.run_command(['hardware', 'detail', '100', '--components'])
self.assert_no_fail(result)
def test_sensor(self):
result = self.run_command(['hardware', 'sensor', '100'])
self.assert_no_fail(result)
def test_sensor_discrete(self):
result = self.run_command(['hardware', 'sensor', '100', '--discrete'])
self.assert_no_fail(result)
def test_monitoring(self):
result = self.run_command(['hardware', 'monitoring', '100'])
self.assert_no_fail(result)
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_check_for_closing(self, confirm_mock):
confirm_mock.return_value = True
result = self.run_command(['vs', 'create', '--hostname', 'TEST', '--domain', 'TESTING',
'--flavor', 'B1_2X8X25', '--datacenter', 'ams01', '--os', 'UBUNTU_LATEST'])
self.assert_no_fail(result)
self.assertIn('Warning: Closed soon: ams01', result.output)
result = self.run_command(['vs', 'create', '--hostname', 'TEST', '--domain', 'TESTING',
'--flavor', 'B1_2X8X25', '--datacenter', 'mex01', '--os', 'UBUNTU_LATEST'])
self.assert_no_fail(result)
self.assertNotIn('Warning: Closed soon: mex01', result.output)
def test_notifications(self):
result = self.run_command(['hardware', 'notifications', '100'])
self.assert_no_fail(result)
def test_add_notification(self):
result = self.run_command(['hardware', 'notification-add', '100', '--users', '123456'])
self.assert_no_fail(result)
def test_notification_delete(self):
result = self.run_command(['hardware', 'notification-delete', '100'])
self.assert_no_fail(result)
def test_create_credential(self):
result = self.run_command(['hw', 'create-credential', '123456',
'--username', 'testslcli', '--password', 'test-123456',
'--notes', 'test slcli', '--software', 'system'])
self.assert_no_fail(result)
def test_list_hw_search_noargs(self):
result = self.run_command(['hw', 'list', '--search'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Search', 'advancedSearch', args=('_objectType:SoftLayer_Hardware ',))
def test_list_hw_search_noargs_domain(self):
result = self.run_command(['hw', 'list', '--search', '-Dtest'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Search', 'advancedSearch',
args=('_objectType:SoftLayer_Hardware domain: *test*',))
@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_hardware_cancel_no_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hardware', 'cancel', '102'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted', result.exception.message)
|