|
| 1 | +import inspect |
| 2 | +import unittest |
| 3 | + |
| 4 | +from absl import flags |
| 5 | +import mock |
| 6 | +from perfkitbenchmarker import errors |
| 7 | +from perfkitbenchmarker import provider_info |
| 8 | +from perfkitbenchmarker import sql_engine_utils |
| 9 | +from perfkitbenchmarker import vm_util |
| 10 | +from perfkitbenchmarker.providers.azure import azure_network |
| 11 | +from tests import pkb_common_test_case |
| 12 | + |
| 13 | +FLAGS = flags.FLAGS |
| 14 | + |
| 15 | + |
| 16 | +class AzureFlexibleServerCreateTestCase(pkb_common_test_case.PkbCommonTestCase): |
| 17 | + |
| 18 | + def setUp(self): |
| 19 | + super().setUp() |
| 20 | + FLAGS.cloud = provider_info.AZURE |
| 21 | + FLAGS.run_uri = 'test_run_uri' |
| 22 | + mock_resource_group = mock.Mock() |
| 23 | + self.resource_group_patch = self.enter_context( |
| 24 | + mock.patch.object(azure_network, 'GetResourceGroup') |
| 25 | + ) |
| 26 | + self.resource_group_patch.return_value = mock_resource_group |
| 27 | + mock_resource_group.name = 'az_resource' |
| 28 | + self.mock_command = self.enter_context( |
| 29 | + mock.patch.object(vm_util, 'IssueCommand') |
| 30 | + ) |
| 31 | + self.mock_command.return_value = (None, '', None) |
| 32 | + |
| 33 | + def testCreatePostgres(self): |
| 34 | + yaml_spec = inspect.cleandoc(f""" |
| 35 | + sysbench: |
| 36 | + relational_db: |
| 37 | + cloud: {provider_info.AZURE} |
| 38 | + engine: {sql_engine_utils.FLEXIBLE_SERVER_POSTGRES} |
| 39 | + engine_version: '13' |
| 40 | + db_tier: GeneralPurpose |
| 41 | + db_spec: |
| 42 | + {provider_info.AZURE}: |
| 43 | + machine_type: Standard_D2ds_v4 |
| 44 | + zone: eastus |
| 45 | + db_disk_spec: |
| 46 | + {provider_info.AZURE}: |
| 47 | + disk_size: 128 |
| 48 | + provisioned_iops: 1000 |
| 49 | + vm_groups: |
| 50 | + clients: |
| 51 | + vm_spec: *default_dual_core |
| 52 | + disk_spec: *default_500_gb |
| 53 | + """) |
| 54 | + bm_spec = pkb_common_test_case.CreateBenchmarkSpecFromYaml( |
| 55 | + yaml_spec, 'sysbench' |
| 56 | + ) |
| 57 | + bm_spec.ConstructRelationalDb() |
| 58 | + |
| 59 | + bm_spec.relational_db._Create() |
| 60 | + metadata = bm_spec.relational_db.GetResourceMetadata() |
| 61 | + |
| 62 | + cmd = ' '.join(self.mock_command.call_args[0][0]) |
| 63 | + with self.subTest(name='StorageType'): |
| 64 | + self.assertIn('--storage-type Premium_LRS', cmd) |
| 65 | + with self.subTest(name='Iops'): |
| 66 | + self.assertIn('--iops 1000', cmd) |
| 67 | + with self.subTest(name='Metadata'): |
| 68 | + self.assertEqual(metadata['disk_type'], 'Premium_LRS') |
| 69 | + |
| 70 | + def testCreateMysql(self): |
| 71 | + yaml_spec = inspect.cleandoc(f""" |
| 72 | + sysbench: |
| 73 | + relational_db: |
| 74 | + cloud: {provider_info.AZURE} |
| 75 | + engine: {sql_engine_utils.FLEXIBLE_SERVER_MYSQL} |
| 76 | + engine_version: '8.0' |
| 77 | + db_tier: GeneralPurpose |
| 78 | + db_spec: |
| 79 | + {provider_info.AZURE}: |
| 80 | + machine_type: Standard_D2ds_v4 |
| 81 | + zone: eastus |
| 82 | + db_disk_spec: |
| 83 | + {provider_info.AZURE}: |
| 84 | + disk_size: 128 |
| 85 | + provisioned_iops: 1000 |
| 86 | + vm_groups: |
| 87 | + clients: |
| 88 | + vm_spec: *default_dual_core |
| 89 | + disk_spec: *default_500_gb |
| 90 | + """) |
| 91 | + bm_spec = pkb_common_test_case.CreateBenchmarkSpecFromYaml( |
| 92 | + yaml_spec, 'sysbench' |
| 93 | + ) |
| 94 | + bm_spec.ConstructRelationalDb() |
| 95 | + |
| 96 | + bm_spec.relational_db._Create() |
| 97 | + metadata = bm_spec.relational_db.GetResourceMetadata() |
| 98 | + |
| 99 | + cmd = ' '.join(self.mock_command.call_args[0][0]) |
| 100 | + with self.subTest(name='AutoScaleIops'): |
| 101 | + self.assertIn('--auto-scale-iops Disabled', cmd) |
| 102 | + with self.subTest(name='Metadata'): |
| 103 | + self.assertEqual(metadata['autoscale_iops'], 'Disabled') |
| 104 | + |
| 105 | + def testConstructMysqlWithThroughputRaises(self): |
| 106 | + yaml_spec = inspect.cleandoc(f""" |
| 107 | + sysbench: |
| 108 | + relational_db: |
| 109 | + cloud: {provider_info.AZURE} |
| 110 | + engine: {sql_engine_utils.FLEXIBLE_SERVER_MYSQL} |
| 111 | + engine_version: '8.0' |
| 112 | + db_tier: GeneralPurpose |
| 113 | + db_spec: |
| 114 | + {provider_info.AZURE}: |
| 115 | + machine_type: Standard_D2ds_v4 |
| 116 | + zone: eastus |
| 117 | + db_disk_spec: |
| 118 | + {provider_info.AZURE}: |
| 119 | + disk_size: 128 |
| 120 | + provisioned_iops: 1000 |
| 121 | + provisioned_throughput: 200 |
| 122 | + vm_groups: |
| 123 | + clients: |
| 124 | + vm_spec: *default_dual_core |
| 125 | + disk_spec: *default_500_gb |
| 126 | + """) |
| 127 | + bm_spec = pkb_common_test_case.CreateBenchmarkSpecFromYaml( |
| 128 | + yaml_spec, 'sysbench' |
| 129 | + ) |
| 130 | + with self.assertRaises(errors.Config.InvalidValue): |
| 131 | + bm_spec.ConstructRelationalDb() |
| 132 | + |
| 133 | + |
| 134 | +if __name__ == '__main__': |
| 135 | + unittest.main() |
0 commit comments