Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BotService: Bugfixing, code refactoring, reorganization and UX revamping #7924

Merged
merged 47 commits into from
Nov 28, 2018
Merged

BotService: Bugfixing, code refactoring, reorganization and UX revamping #7924

merged 47 commits into from
Nov 28, 2018

Conversation

carlosscastro
Copy link
Contributor

@carlosscastro carlosscastro commented Nov 27, 2018

The code grew organically and it was time to do some refactors to improve maintainability and provide a more robust experience. We observe very high usage of the bot service CLI, so we are going to invest in this strategic tool moving forward. This Pr contains:

  • Refactor of large methods into classes with single responsibilities. Modular design allows us to add unit tests in the upcoming releases.
  • Test coverage: Adding end to end tests to now cover for most bot management scenarios. Unit tests to come in next release, but still a huge improvement in automated coverage.
  • User Experience: Adding an extremely easy-to-debug bot management experience.

Again, note the core of the code remains unchanged, but reorganized. We did simplifications and bug fixes from bugs that 1) users reported in this repo and other repos or stack overflow and 2) bugs that we found in our new tests.


This checklist is used to make sure that common guidelines for a pull request are followed.

  • The PR has modified HISTORY.rst describing any customer-facing, functional changes. Note that this does not include changes only to help content. (see Modifying change log).

  • I adhere to the Command Guidelines.

@tjprescott
Copy link
Member

Does this PR fix any of the open in issues in this repo?
https://github.com/Azure/azure-cli/issues?q=is%3Aopen+is%3Aissue+label%3ABotService

@@ -13,6 +13,8 @@

name_arg_type = CLIArgumentType(metavar='NAME', configured_default='botname', id_part='Name')

supported_languages = ['Csharp', 'Node']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not an enum in your SDK (which is another way of saying, why isn't this specified in Swagger)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is not information that flows in the swagger, but higher level information. As you may know, we offer the basic CRUD operations for bot such as Create / Update / delete / Show but also some other operations that are outside of the basic crud such as Download and Publish for downloading and publishing bots. The languages are a construct of download and publish, but crud operations don't need to know the language generally.

The other scenario where languages are known is when we create a website for the bot (bot.kind == webapp). In which case we use the language to decide which bot template to publish to the website, but again it does not interact with our arm api.

Hope that makes sense, I'm happy to elaborate further.

logger = get_logger(__name__)


class AdalAuthenticator:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yugangw-msft for auth-related code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, This code was already in the core CLI, I just refactored it into an external class because it was mingled with the bot creation code.

The purpose of this is, to create a bot we need a Microsoft Application Id. Users can either a) provide an id or b) ask us to provision one for them, case in which we authenticate to request permissions to provision an application and we create it and use it for the bot.

But again this was in custom.py before this PR so you already reviewed it likely.

Happy to provide more details!

@carlosscastro
Copy link
Contributor Author

carlosscastro commented Nov 27, 2018

Hello @tjprescott, thanks for your review.

A large part of our user base uses botbuilder-tools to file issues so we are fixing a lot of bugs from there. I followed up on all bugs on this repo. They are mostly questions though, but I'll re-check one by one to see which are fixed. But overall we are fixing tens of bugs we found and adding a much better user experience. Since we've been using the extension, the bits published now in the core CLI for botservice are not in a great shape, so this will be a huge improvement for users.

Question regarding the build failure on this PR. We are getting the error below, but I don't see any error in my local computer. How can I reproduce this command locally to work faster? Also any hints of what the error could be here?

1.0.2 wcwidth-0.1.7 websocket-client-0.54.0 whoosh-2.7.4 xmltodict-0.11.0 yarl-1.2.6
Initializing linter with command table and help files...
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/bin/azdev", line 11, in <module>
    load_entry_point('azure-cli-dev-tools', 'console_scripts', 'azdev')()
  File "/home/travis/build/Azure/azure-cli/tools/automation/__main__.py", line 25, in main
    args.func(args)
  File "/home/travis/build/Azure/azure-cli/tools/automation/cli_linter/__init__.py", line 38, in main
    create_invoker_and_load_cmds_and_args(az_cli)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/azure/cli/core/file_util.py", line 57, in create_invoker_and_load_cmds_and_args
    invoker.commands_loader.load_arguments(command)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 253, in load_arguments
    self.command_table[command].load_arguments()  # this loads the arguments via reflection
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 141, in load_arguments
    super(AzCliCommand, self).load_arguments()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/knack/commands.py", line 76, in load_arguments
    cmd_args = self.arguments_loader()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 444, in default_arguments_loader
    op = handler or self.get_op_handler(operation)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 489, in get_op_handler
    op = import_module(mod_to_import)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/azure/cli/command_modules/botservice/bot_operations.py", line 10, in <module>
    from azure.cli.command_modules.botservice.auth import converged_app
ModuleNotFoundError: No module named 'azure.cli.command_modules.botservice.auth'

@stevengum
Copy link
Contributor

@tjprescott do you have any feedback on this import error?

In the latest build for the 2.7 Automation, the tests are not being imported properly due to the following reason: "Reason: No module named cli.core"

==================
Discover Tests
==================
�[0m
�[0mUnable to import azure.cli.command_modules.botservice.tests.latest.test_authsetting_commands. Reason: No module named cli.core�[0m
�[0mUnable to import azure.cli.command_modules.botservice.tests.latest.test_channel_commands. Reason: No module named cli.core�[0m
�[0mUnable to import azure.cli.command_modules.botservice.tests.latest.test_bot_commands. Reason: No module named cli.core�[0m

The log can be found here: https://api.travis-ci.org/v3/job/460375761/log.txt

@tjprescott
Copy link
Member

For this ModuleNotFoundError: No module named 'azure.cli.command_modules.botservice.auth' you likely need to add it to the package list in your setup.py file. Same for the other subdirectories you created in your refactoring.

@stevengum
Copy link
Contributor

stevengum commented Nov 27, 2018

For this ModuleNotFoundError: No module named 'azure.cli.command_modules.botservice.auth' you likely need to add it to the package list in your setup.py file. Same for the other subdirectories you created in your refactoring.

I managed to get this in with this commit, so that error should go away. There was a similar error popping up for tests/latest/tools/, but I was hesitant to add the following to the setup.py file:

'azure.cli.command_modules.botservice.tests',
'azure.cli.command_modules.botservice.tests.latest',
'azure.cli.command_modules.botservice.tests.latest.tools'

My hesitance stems from the fact that we don't want to expose the testing apparatuses to users to use; is there a workaround that we can use for the test folders? perhaps just from .tools.directline_client import DirectLineClient?

@tjprescott
Copy link
Member

tjprescott commented Nov 27, 2018

In the test folders for the resource module, we have to reference certain JSON files. We do something like:

curr_dir = os.path.dirname(os.path.realpath(__file__))
os.path.join(curr_dir, 'foo.json').replace('\\', '\\\\')

That may or may not help with your scenario.

Swagat Mishra and others added 23 commits November 27, 2018 21:54
…d more informational logging as well. General improvements in already existing user messages. Add additional tests.
@carlosscastro
Copy link
Contributor Author

Thanks for your help with the build @tjprescott. We found some issues in python 2.7 when the folder structure was more nested so we just made it flattened as before.

@tjprescott tjprescott added this to the Sprint 50 milestone Nov 28, 2018
@yugangw-msft yugangw-msft merged commit 0729c9f into Azure:dev Nov 28, 2018
williexu pushed a commit to williexu/azure-cli that referenced this pull request Dec 4, 2018
williexu pushed a commit that referenced this pull request Dec 6, 2018
* fix live tests for sas token urls to use datetime (#7866)

* Convert test back to scenario test. (#7862)

* Remove unused scripts. (#7860)

* fix get curren user id azure-graphrbac Breaking change fixes #7839 (#7864)

* Use knack 0.5.1. (#7780)

* test: make webjob tests record only as create command is unavailable (#7870)

* Deprecate expand param. (#7868)

* Updated help.py - generate-sas example (#7873)

Added MacOS example for generating SAS token with expiration time. The call to the date function `date -d` works on Linux, but not on MacOS. I provided MacOS sample.

* Low priority vmss test and help update. (#7882)

Updated help text and test location for low priority vmss

* Added --force to az vm restart. Added simple test. (#7885)

* Fix requests version > 2.20 (#7858)

* Bump CLI versions

* [vm] Enable password and ssh key authentication during linux VM creation (#7863)

* authentication-type can be set to all to permit both ssh key and password authentication

* Added tests and updated authentication type validation error.

* Added history entry, bumped version. Checked out file recording from dev branch.

* Addressed PEP8 issues.

* Updated test_vm_defaults auth tests.

* Updated other profile's unittests.

* Now infers authentication_type, other updates. Do not need to explicitly pass  all.

* Updated help text.
Fix conflict by checking out ephemeral os disk recording from dev branch.

* Style changes.

* Properly handle parsing of ids from -o tsv on windows. (#7898)

* Properly handle parsing of ids from -o tsv on windows.

* Removed unused import.

* [Storage] bump mgmt sdk version to 3.1.0 and set new api-version to use. (#7869)

* changed api-version in recordings and set to new ver of sdk

* version bump and history

* fix immutability test

* re-record all

* fixed recordings

fix recording

* bumped version after release

* test: live test fixes in appservice, vm, resource (#7899)

* ci: fix build break (#7900)

* Updated adls version (#7859)

* core: support cross tenant resource provisioning for multi-tenant service principal (#7916)

* core: fix the error on matching SP creds (#7923)

* resource: fix live test failure of policyset (#7922)

* [CI] reenable extension checking in CI (#7933)

* reenable extension checking in CI

minor edit to get travis to run

edit

* minor edit

* BotService: Bugfixing, code refactoring, reorganization and UX revamping (#7924)

* Close #7528. (#7920)

* Minor updates to core/generate_ssh_keys and batchai/_generate_ssh_keys (#7895)

* [image] create. Add --os-disk-caching parameter. (#7919)

* graph: support custom key identifier (#7913)

* support key-id description

* linter error fixes

* consolidate

* use official sdk

* update history

* BotService: fix tests, improve test robustness and update recordings (#7941)

* BotService: fix tests, mprove test robustness and update recordings

* BotService; fixing tests

* BotService: Update recordings

* webapp: Adding support for az webapp up (#7930)

* core: fix a breaking in kv when run under service principal (#7946)

* Disable version check from CI. (#7958)

* test: add test coverage for regression from auth (#7949)

* core: fix a breaking in kv when run under service principal

* test: add test coverage for regression from auth

* [AKS] Remove "(PREVIEW)" from AAD arguments  (#7960)

* [AKS] Remove "(PREVIEW)" from AAD arguments

* Bump module version and update HISTORY.rst

* Bug fixes for azure-cli-botservice (#7956)

* Az bot: fix bug when publishing Node.js bots, fix minor bugs

* Az bot: rerecord BotTests

* Az bot: fix static check error

* [core] Updated location help text (#7951)

* Updated location help text.

* Update parameters.py

* EventHubs help fixes (#7961)

* EventHubs help fixes

#Fixes 7937. Fixes #7938.

* Update _help.py

* Fixes for VPN Client Generate (#7962)

* Remove mock dependency.

* Fix linter issues.

* Condense the table format for task list and change all column headers to NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants