|
14 | 14 | # |
15 | 15 |
|
16 | 16 | from f5.multi_device.cluster import TrustDomain |
| 17 | +from f5.multi_device.exceptions import DeviceAlreadyInTrustDomain |
17 | 18 | from f5.multi_device.exceptions import DeviceNotTrusted |
18 | 19 |
|
19 | 20 | import mock |
@@ -54,3 +55,77 @@ def test_validate_device_not_trusted(TrustDomainCreateNew): |
54 | 55 | td.validate() |
55 | 56 | assert "'test' is not trusted by 'test', which trusts: []" in \ |
56 | 57 | ex.value.message |
| 58 | + |
| 59 | + |
| 60 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain._set_attributes') |
| 61 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain.validate') |
| 62 | +def test___init__(mock_set_attr, mock_validate, BigIPs): |
| 63 | + mock_bigips = BigIPs |
| 64 | + td = TrustDomain(devices=mock_bigips) |
| 65 | + assert td._set_attributes.call_args == mock.call(devices=mock_bigips) |
| 66 | + |
| 67 | + |
| 68 | +def test__set_attributes(BigIPs): |
| 69 | + mock_bigips = BigIPs |
| 70 | + td = TrustDomain() |
| 71 | + td._set_attributes(devices=mock_bigips, partition='test') |
| 72 | + assert td.devices == mock_bigips |
| 73 | + assert td.partition == 'test' |
| 74 | + assert td.device_group_name == 'device_trust_group' |
| 75 | + assert td.device_group_type == 'sync-only' |
| 76 | + |
| 77 | + |
| 78 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain._add_trustee') |
| 79 | +@mock.patch('f5.multi_device.trust_domain.pollster') |
| 80 | +def test_create(mock_add_trustee, mock_pollster, TrustDomainCreateNew): |
| 81 | + td, mock_bigips = TrustDomainCreateNew |
| 82 | + td.create(devices=mock_bigips, partition='test') |
| 83 | + assert td.devices == mock_bigips |
| 84 | + assert td.partition == 'test' |
| 85 | + assert td._add_trustee.call_args_list == \ |
| 86 | + [ |
| 87 | + mock.call(mock_bigips[1]), |
| 88 | + mock.call(mock_bigips[2]), |
| 89 | + mock.call(mock_bigips[3]) |
| 90 | + ] |
| 91 | + |
| 92 | + |
| 93 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain._add_trustee') |
| 94 | +@mock.patch('f5.multi_device.trust_domain.pollster') |
| 95 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain._remove_trustee') |
| 96 | +def test_teardown( |
| 97 | + mock_add_trustee, mock_pollster, mock_rem_trustee, TrustDomainCreateNew |
| 98 | +): |
| 99 | + td, mock_bigips = TrustDomainCreateNew |
| 100 | + td.create(devices=mock_bigips, partition='test') |
| 101 | + td.teardown() |
| 102 | + assert td.domain == {} |
| 103 | + assert td._remove_trustee.call_args_list == \ |
| 104 | + [ |
| 105 | + mock.call(mock_bigips[0]), |
| 106 | + mock.call(mock_bigips[1]), |
| 107 | + mock.call(mock_bigips[2]), |
| 108 | + mock.call(mock_bigips[3]) |
| 109 | + ] |
| 110 | + |
| 111 | + |
| 112 | +@mock.patch('f5.multi_device.trust_domain.get_device_info') |
| 113 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain._modify_trust') |
| 114 | +def test__add_trustee(mock_dev_info, mock_mod_trust, TrustDomainCreateNew): |
| 115 | + td, mock_bigips = TrustDomainCreateNew |
| 116 | + td._set_attributes(devices=mock_bigips, partition='test') |
| 117 | + td._add_trustee(mock_bigips[1]) |
| 118 | + assert td._modify_trust.call_args == \ |
| 119 | + mock.call(mock_bigips[0], td._get_add_trustee_cmd, mock_bigips[1]) |
| 120 | + |
| 121 | + |
| 122 | +@mock.patch('f5.multi_device.trust_domain.TrustDomain._modify_trust') |
| 123 | +def test__add_trustee_already_in_domain( |
| 124 | + mock_mod_trust, TrustDomainCreateNew |
| 125 | +): |
| 126 | + td, mock_bigips = TrustDomainCreateNew |
| 127 | + td._set_attributes(devices=mock_bigips, partition='test') |
| 128 | + td.domain = {'test': 'device'} |
| 129 | + with pytest.raises(DeviceAlreadyInTrustDomain) as ex: |
| 130 | + td._add_trustee(mock_bigips[1]) |
| 131 | + assert "Device: 'test' is already in this trust domain" in ex.value.message |
0 commit comments