|
16 | 16 | import openpyxl # Not directly used but this will make sure it is installed |
17 | 17 | import argparse |
18 | 18 |
|
19 | | - from azure.storage.file import ( |
20 | | - ContentSettings, |
21 | | - FileService, |
22 | | - ) |
23 | | - from azure.storage.blob import ( |
24 | | - BlobServiceClient, |
25 | | - BlobClient, |
26 | | - ContainerClient |
27 | | - ) |
28 | | - from azure.identity import DefaultAzureCredential |
29 | | - from azure.data.tables import TableServiceClient |
30 | | - |
31 | 19 | except ImportError as e: |
32 | 20 | print("Import error: " + str(e) + "\nPlease install the required modules using pip install -r requirements.txt") |
33 | 21 | exit(1) |
@@ -141,67 +129,6 @@ def set_output_file(self, output_file): |
141 | 129 | self.output_file = output_file |
142 | 130 | def get_output_file(self): |
143 | 131 | return self.output_file |
144 | | - |
145 | | -def upload_blob_to_azure(file_name): |
146 | | - """ |
147 | | - Uploads a file to Azure Blob Storage. |
148 | | -
|
149 | | - Args: |
150 | | - file_name (str): The name of the file to be uploaded. |
151 | | -
|
152 | | - Returns: |
153 | | - None |
154 | | - """ |
155 | | - print("Uploading file to Azure: " + file_name) |
156 | | - account_url = "https://"+ args.storage_account_name +".blob.core.windows.net" |
157 | | - blob_service_client = BlobServiceClient(account_url, credential=args.storage_account_key) |
158 | | - blob_client = blob_service_client.get_blob_client(container=args.container_name, blob=file_name) |
159 | | - with open(file=file_name, mode="rb") as data: |
160 | | - blob_client.upload_blob(data, overwrite=True) |
161 | | - |
162 | | -def download_blob_from_azure(file_name): |
163 | | - """ |
164 | | - Downloads a blob from Azure Blob Storage. |
165 | | -
|
166 | | - Args: |
167 | | - file_name (str): The name of the blob file to download. |
168 | | -
|
169 | | - Returns: |
170 | | - None |
171 | | - """ |
172 | | - account_url = "https://"+ args.storage_account_name +".blob.core.windows.net" |
173 | | - blob_service_client = BlobServiceClient(account_url, credential=args.storage_account_key) |
174 | | - blob_client = blob_service_client.get_blob_client(container=args.container_name, blob=file_name) |
175 | | - with open(file=file_name, mode="wb") as data: |
176 | | - data.write(blob_client.download_blob().readall()) |
177 | | - |
178 | | -def upload_results_to_azure(file_to_upload, file_name, file_directory): |
179 | | - """ |
180 | | - Uploads the results to Azure. |
181 | | -
|
182 | | - Args: |
183 | | - None |
184 | | -
|
185 | | - Returns: |
186 | | - None |
187 | | - """ |
188 | | - print("Upload results to file share: " + file_to_upload) |
189 | | - file_service = FileService(connection_string=args.connection_string) |
190 | | - file_service.create_file_from_path(share_name=args.share_name, file_name=file_name, directory_name=file_directory, local_file_path=file_to_upload, content_settings=ContentSettings(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) |
191 | | - |
192 | | -def download_file_from_azure(out_file_path, file_name, file_directory): |
193 | | - """ |
194 | | - Downloads a file from Azure. |
195 | | -
|
196 | | - Args: |
197 | | - None |
198 | | -
|
199 | | - Returns: |
200 | | - None |
201 | | - """ |
202 | | - file_service = FileService(connection_string=args.connection_string) |
203 | | - file = file_service.get_file_to_path(share_name=args.share_name, file_name=file_name, directory_name=file_directory, file_path=out_file_path) |
204 | | - return file.name |
205 | 132 |
|
206 | 133 | def get_git_root(): |
207 | 134 | """ |
@@ -832,23 +759,8 @@ def compare_health_results(curr_results_path): |
832 | 759 | Returns: |
833 | 760 | None |
834 | 761 | """ |
835 | | - |
836 | | - if not args.connection_string or not args.share_name: |
837 | | - raise Exception("Azure credentials not provided. Cannot compare results.") |
838 | | - |
839 | | - try: |
840 | | - prev_results = 'azure-'+curr_results_path |
841 | | - print_conditionally("Downloading previous results from Azure: " + prev_results) |
842 | | - _ = download_file_from_azure(out_file_path=prev_results, |
843 | | - file_name=curr_results_path, file_directory="") |
844 | | - |
845 | | - except Exception as e: |
846 | | - if "ResourceNotFound" in str(e): |
847 | | - print("No previous results found") |
848 | | - exit(1) |
849 | | - else: |
850 | | - print("Error downloading previous results ") |
851 | | - exit(1) |
| 762 | + |
| 763 | + prev_results = 'azure-'+curr_results_path |
852 | 764 |
|
853 | 765 | prev_results_df = pd.read_excel(prev_results, index_col=0, sheet_name=0) |
854 | 766 | prev_results_codeql_version_df = pd.read_excel(prev_results, index_col=0, sheet_name=1) |
@@ -877,43 +789,16 @@ def compare_health_results(curr_results_path): |
877 | 789 |
|
878 | 790 | diff_results = curr_results_df.compare(prev_results_df, keep_shape=True, result_names=("Current", "Previous")) |
879 | 791 |
|
880 | | - with pd.ExcelWriter("diff" + curr_results_path) as writer: |
881 | | - diff_results.to_excel(writer, sheet_name="Diff") |
882 | | - local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version") |
883 | | - local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs") |
884 | | - local_system_info_df.to_excel(writer, sheet_name="Local System Info") |
885 | | - prev_results_codeql_version_df.to_excel(writer, sheet_name="Last Stored CodeQL Version") |
886 | | - prev_results_codeql_packs_df.to_excel(writer, sheet_name="Last Stored CodeQL Packs") |
887 | | - prev_results_local_system_info_df.to_excel(writer, sheet_name="Last Stored System Info") |
888 | | - print_conditionally("Saved diff results") |
889 | | - |
890 | | - if not args.local_result_storage: |
891 | | - # upload new results to Azure |
892 | | - if args.overwrite_azure_results: |
893 | | - print("!! Overwriting Azure results !!") |
894 | | - print("Type 'yes' to confirm") |
895 | | - confirm = input() |
896 | | - if confirm != "yes": |
897 | | - print("Exiting") |
898 | | - exit(1) |
899 | | - else: |
900 | | - double_confirm = input("Are you sure?") |
901 | | - if double_confirm != "yes": |
902 | | - print("Exiting") |
903 | | - exit(1) |
904 | | - |
905 | | - if args.overwrite_azure_results: |
906 | | - print_conditionally("Uploading results") |
907 | | - upload_results_to_azure(file_to_upload=curr_results_path, |
908 | | - file_name=curr_results_path, file_directory="") |
909 | | - # upload diff to Azure |
910 | | - print_conditionally("Uploading diff results") |
911 | | - upload_results_to_azure(file_to_upload="diff" + curr_results_path, |
912 | | - file_name="diff" + curr_results_path, file_directory="") |
913 | | - |
914 | 792 | if not all(diff_results.isnull().all()) : |
915 | 793 | print("Differences found in results!") |
916 | | - exit(1) |
| 794 | + with pd.ExcelWriter("diff" + curr_results_path) as writer: |
| 795 | + diff_results.to_excel(writer, sheet_name="Diff") |
| 796 | + local_codeql_version_df.to_excel(writer, sheet_name="Local CodeQL Version") |
| 797 | + local_codeql_packs_df.to_excel(writer, sheet_name="Local CodeQL Packs") |
| 798 | + local_system_info_df.to_excel(writer, sheet_name="Local System Info") |
| 799 | + prev_results_codeql_version_df.to_excel(writer, sheet_name="Last Stored CodeQL Version") |
| 800 | + prev_results_codeql_packs_df.to_excel(writer, sheet_name="Last Stored CodeQL Packs") |
| 801 | + prev_results_local_system_info_df.to_excel(writer, sheet_name="Last Stored System Info") |
917 | 802 | else: |
918 | 803 | print("No differences found in results") |
919 | 804 | # delete downloaded file |
@@ -1011,14 +896,7 @@ def find_sln_file(path): |
1011 | 896 | parser.add_argument('-i', '--individual_test', help='Run only the tests with <name> in the name', type=str, required=False) |
1012 | 897 | parser.add_argument('-m', '--compare_results', help='Compare results to previous run', action='store_true', required=False) |
1013 | 898 | parser.add_argument('--compare_results_no_build',help='Compare results to previous run',type=str,required=False,) |
1014 | | - parser.add_argument('--container_name',help='Azure container name',type=str,required=False, ) |
1015 | | - parser.add_argument('--storage_account_name',help='Azure storage account name',type=str,required=False, ) |
1016 | | - parser.add_argument('--share_name', help='Azure share name',type=str,required=False,) |
1017 | | - parser.add_argument('--storage_account_key',help='Azure storage account key',type=str,required=False, ) |
1018 | | - parser.add_argument('--connection_string', help='Azure connection string', type=str, required=False,) |
1019 | | - parser.add_argument('--local_result_storage',help='Store results locally instead of in Azure',action='store_true',required=False,) |
1020 | 899 | parser.add_argument('--codeql_path', help='Path to the codeql executable',type=str,required=False,) |
1021 | | - parser.add_argument('--overwrite_azure_results', help='Overwrite Azure results',action='store_true',required=False,) |
1022 | 900 | parser.add_argument('--build_database_only', help='Build database only',action='store_true',required=False,) |
1023 | 901 | args = parser.parse_args() |
1024 | 902 |
|
|
0 commit comments